我正在尝试在发布构建类型上运行仪器测试。我的设置如下:
Android Studio - 3.4.1
Android Gradle Plugin - 3.4.1
Gragle - 5.4.1
R8 - Enabled (default)
相关build.gradle片段:
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
}
}
proguard-rules-test.pro 的内容(用于测试目的):
-keep public class ** { *; }
运行任何检测都会导致以下运行时异常:
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扩展MyApplication并被AndroidJUnitRunner调用)
将-keep行从proguard-rules-test.pro移动到主 Proguard 规则文件中,可以使测试运行并顺利通过。
有任何想法吗?