Issue
So I'm getting a NoSuchMethodError
when running my Activity/instrumentation tests from Android Studio, on the code line which tries to call a method in a library module from the 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's the deal here? I've defined my library as a "compile"-dependency in build.gradle, and it's compiling just fine. The library is also invoked from the main app classes without problems. It's only when I call it from the tests it fails. My app and my tests are in the same module.
I've tried running the clean task, the assembleDebug and assembleDebugTest tasks manually. No avail.
Project structure:
Root
|---MyApp
| |---src/main/...
| |---src/androidTest/...
|----MyLibrary
Running Android Studio v1.0.2 Gradle build tools v1.0.0 Running as an "Android Test" on module "MyApp" from the Run/Debug configurations of AS with default Instrumentation test runner.
Solution
Ok this one was a bit tricky. Keyword: proguard minify. Since the newly implemented method so far only was used by the instrumentation test, proguard didn't pick up on its usage and therefore removed it from the DEX in the proguardDebugTest build step.
Solution: Either disable minification in the debug build (In gradle: android.buildTypes.debug.minifyEnabled false
), or use the method in the main app.
Answered By - Nilzor
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.