I'm trying to run instrumentation tests on a release build type. My setup is as follows:
Android Studio - 3.4.1
Android Gradle Plugin - 3.4.1
Gragle - 5.4.1
R8 - Enabled (default)
Relevant build.gradle snippet:
testBuildType "release"
buildTypes {
release {
proguardFiles fileTree(dir: 'vendor', include: ['*.pro']).asList().toArray()
debuggable true
minifyEnabled true
shrinkResources true
signingConfig signingConfigs.release
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
testProguardFile 'proguard-rules-test.pro'
testCoverageEnabled false
}
}
Content of proguard-rules-test.pro (for test purposes):
-keep public class ** { *; }
Running any instrumentation results in the following runtime exception:
com.MYAPP.debug E/InstrumentationResultPrinter: Failed to mark test No Tests as finished after process crash
com.MYAPP.debug E/MonitoringInstr: Exception encountered by: Thread[main,5,main]. Dumping thread state to outputs and pining for the fjords.
java.lang.NoSuchMethodError: No virtual method setAppComponent(L/com/MYAPP/injection/AppComponent;)V in class L/com/MYAPP/data/common/MyApplication$Companion; or its super classes (declaration of 'com.MYAPP.data.common.MyApplication$Companion' appears in /data/app/com.MYAPP.debug-o3QrzyIOGC0Ko3XRS2fcxQ==/base.apk)
at com.MYAPP.base.TestMyApplication.h(TestMyApplication.kt:20)
at com.MYAPP.data.common.MyApplication.onCreate(MyApplication.kt:126)
(TestMyApplication extends MyApplication and being called by AndroidJUnitRunner)
Moving the -keep line from proguard-rules-test.pro into the main Proguard rule file makes the tests to run and pass without issues.
Any ideas?