Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

com.android.tools.r8.utils.AbortException zza already has a mappin

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
  1. Weirdly not happening on a basic app compile. Not sure why R8 is doing anything w/ test code.
  2. Is this an R8 issue or Play Services issue?
  3. How can I resolve this. A gradle clean + invalidate/restart didn't do anything, nor did manually deleting and regenerating the mappings.txt file.
like image 226
tir38 Avatar asked Dec 10 '22 02:12

tir38


2 Answers

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.

like image 79
MortenKJ Avatar answered Jan 12 '23 22:01

MortenKJ


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.

like image 37
Boris Staykov Avatar answered Jan 12 '23 21:01

Boris Staykov