I'm running instrumentation tests and getting this compile error:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app:transformClassesAndResourcesWithR8ForDebugAndroidTest'.
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$3.accept(ExecuteActionsTaskExecuter.java:151)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter$3.accept(ExecuteActionsTaskExecuter.java:148)
at org.gradle.internal.Try$Failure.ifSuccessfulOrElse(Try.java:191)
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:141)
...
Caused by: java.lang.RuntimeException: com.android.tools.r8.CompilationFailedException: Compilation failed to complete
at com.android.builder.profile.Recorder$Block.handleException(Recorder.java:55)
at com.android.builder.profile.ThreadRecorder.record(ThreadRecorder.java:108)
at com.android.build.gradle.internal.pipeline.TransformTask.transform(TransformTask.java:230)
at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:103)
at org.gradle.api.internal.project.taskfactory.IncrementalTaskInputsTaskAction.doExecute(IncrementalTaskInputsTaskAction.java:46)
...
Caused by: com.android.tools.r8.CompilationFailedException: Compilation failed to complete
at com.android.tools.r8.utils.z.a(:55)
at com.android.tools.r8.R8.runForTesting(:3)
at com.android.tools.r8.R8.run(:3)
at com.android.builder.dexing.R8Tool.runR8(r8Tool.kt:195)
Caused by: com.android.tools.r8.utils.AbortException: Error: offset: 0, line: 16559, column: 1, 'void zza(com.google.android.gms.common.internal.BaseGmsClient,int,android.os.IInterface)' already has a mapping
at com.android.tools.r8.utils.Reporter.a(:21)
at com.android.tools.r8.naming.SeedMapper$a.build(:1)
...
If I look in app/build/outputs/mappings/debug/mapping.txt
I see that method listed twice.
com.google.android.gms.common.internal.BaseGmsClient -> com.google.android.gms.common.internal.BaseGmsClient:
...
344:344:void zza(com.google.android.gms.common.internal.BaseGmsClient,int,android.os.IInterface) -> zza
...
350:350:void zza(com.google.android.gms.common.internal.BaseGmsClient,int,android.os.IInterface) -> zza
I may have some answers.
Regarding 1. If you compile you app with minifyEnabled set to true and run instrumentation tests afterwards, your app may have minified classes, methods etc. All tests therefore needs to be recompiled with R8 to have all minified names corrected in your tests. Concretely, you tests are being compiled by R8 with you app on library-path and a proguard configuration that says -applymapping .
Regarding 2. This is an R8 issue. You might have some luck by adding the following to your project level build.gradle file:
buildscript {
repositories {
maven {
url 'http://storage.googleapis.com/r8-releases/raw'
}
}
dependencies {
classpath 'com.android.tools:r8:1.5.45' // Must be before the Gradle Plugin for Android.
classpath 'com.android.tools.build:gradle:X.Y.Z' // Your current AGP version.
}
}
Regarding 3. If the fix in 2. is not working, you can follow the following bug at the R8 bug-tracker: https://issuetracker.google.com/issues/122924648
It may also be possible to live without instrumentation on the minified app until the issue is resolved.
I have the exact same error and the suggestions from @MortenKJ didn't work for me.
My workaround is not very satisfying but it is the best I can do right now. Whenever I want to run instrumentation tests, I set minifyEnabled
to false
and minSdkVersion
to 21
(for this sdk version multidex
is enabled by default and there is no error that the dex method limit is reached).
Instrumentation tests run as expected now.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With