Android Instrumentation test does not find classes from library project

So, I get NoSuchMethodErrorwhen I run my Activity / Instrument tests from Android Studio, on a code line that tries to call a method in the library module from unit test.

So this is my test:

public class MainActivityTest extends ActivityInstrumentationTestCase2 {
    public void testMainActivity() {
        final MainActivity target = (MainActivity) getActivity();
        MyLibarary.someStaticMethod(); // yields java.lang.NoSuchMethodError
}

What is the deal here? I defined my library as a “compile” dependency in build.gradle and it compiles just fine. The library is also called from the main application classes without any problems. This is only when I call it from the tests, it fails. My application and my tests are in the same module.

I tried to perform the clean, assembleDebug and assembleDebugTest task manually. No.

Project Structure:

Root
 |---MyApp 
 |     |---src/main/...
 |     |---src/androidTest/...
 |----MyLibrary

Android Studio v1.0.2 Gradle v1.0.0 " Android" "MyApp" Run/Debug AS .

+4
2

, . : proguard minify. - , proguard DEX proguardDebugTest.

. (In gradle: android.buildTypes.debug.minifyEnabled false), .

+7

Gradle. , testCompile androidTestCompile, build.gradle, .

:

http://gradle.org/docs/current/userguide/java_plugin.html

Gradle Android

,

+1

All Articles