My app recently enabled the R8. My app can run fine when R8 is enabled. The UI Test can run when R8 is disabled, but when enabled, I got the "Caused by: java.lang.ClassNotFoundException: Didn't find class "com.myapp.staff.CustomTestRunner"".
This is my build-type declaration:
buildTypes{
...
create("instrumentedTest") {
isMinifyEnabled = true
isShrinkResources = false
extra.apply{
set("enableCrashlytics", false)
}
manifestPlaceholders["crashlyticsCollectionEnabled"] = false
configure<CrashlyticsExtension> {
mappingFileUploadEnabled = false
}
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
testProguardFiles("proguard-test-rules.pro")
}
}
This is the error message:
java.lang.RuntimeException: Unable to instantiate instrumentation ComponentInfo{com.myapp.test/com.myapp.FCBTestRunner}: java.lang.ClassNotFoundException: Didn't find class "com.myapp.FCBTestRunner" on path: DexPathList[[zip file "/system/framework/android.test.runner.jar", zip file "/system/framework/android.test.mock.jar", zip file "/system/framework/android.test.base.jar", zip file "/data/app/~~ot6m2KJbJHL_jYouR4mQ7A==/com.myapp.test-RvSjUeMRc0WaoKaPWNYuvA==/base.apk", zip file "/data/app/~~y1oGNjg7y-o2Lyq2z1RnqA==/com.myapp-gxOR-I3OFZEffP9SJyjDEg==/base.apk"],nativeLibraryDirectories=[/system/lib64, /system/system_ext/lib64, /system/product/lib64]]
- I've check the generated mapping file, the CustomTestRunner is not obfuscased.
# {"id":"sourceFile","fileName":"FCBTestRunner.kt"}
0:0:void <clinit>() -> <clinit>
8:8:void <init>() -> <init>
14:14:android.app.Application newApplication(java.lang.ClassLoader,java.lang.String,android.content.Context) -> newApplication
I've check the androidTest.apk by using Android Studio APK Analyzer. The CustomTestRunner is exists inside the com/myapp/staff
I've tried disable the obfuscase to the testProguardFiles by -dontobfuscate.
Change the testProguardFiles:
testProguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro", "proguard-test-rules.pro")