Android R8: Type a.a is defined multiple times
Asked Answered
B

2

8

exact error is

ERROR: /Users/REDACT/.gradle/caches/transforms-4/8d2b49e30523efece47d2329e1531ac9/transformed/classes.jar: R8: Type a.a is defined multiple times: /Users/mgh01/.gradle/caches/transforms-4/8d2b49e30523efece47d2329e1531ac9/transformed/classes.jar:a/a.class, /Users/REDACT/.gradle/caches/transforms-4/196d8149ca78d42bf3bbca1f74e91807/transformed/classes.jar:a/a.class

I've looked up the classes.jar of both and the offending class is just

an

public interface a {}

This is all come off the back of updating the AGP to the latest 8.5.0.

Also running R8 in the "compatibility" mode makes no difference.

I've also tried to disable obfuscation so I can see what a is meant to be but it the same

Any help would be appreciated

Beanpole answered 26/6, 2024 at 8:51 Comment(2)
I'm experiencing the exact same problem. I tried the proposed answer adding @Keep to my classes with no luck. Did you manage to figure it out?Phoenicia
I have the same problem, the latest gradle version which seems to work fine for my project is 8.3.2. Every newer version would lead to the same error. I hope there is some way to fix this.Sculptor
A
2

I had a similar problem and found a fix for my project composed of :

  • an App module

    plugins { id 'com.android.application' }

  • some other library modules

    plugins { id 'com.android.library') }

It worked fine with AGP <= 8.3.2 but stopped working with 8.4.0+

The fix consisted to enable Minification only at the App Level for the release buildType.

In build.gradule (Module: app):

buildTypes {
    debug {
        minifyEnabled false
    }
    release {
        minifyEnabled true
    }
}

and in other modules:

buildTypes {
    debug {
        minifyEnabled false
    }
    release {
        minifyEnabled false
    }
}

I think it may have something to do with the note about "Library classes are shrunk" in the release note of AGP 8.4.0 and the parameter android.disableMinifyLocalDependenciesForLibraries in the gradle.properties (though it didn't work for my project)

cf: https://developer.android.com/build/releases/past-releases/agp-8-4-0-release-notes?hl=fr#library-classes-shrunk

More, in Android builds, R8 is run once during the final stage of building the APK or AAB, which is the step where the entire application is assembled:

The minifyEnabled flag at the app module level means that all the code, including code from library modules, is considered during minification. If library modules have minifyEnabled set to true, they would attempt to minify their code independently, potentially leading to conflicts when the app module tries to do the same during its build process.

Arcboutant answered 30/8, 2024 at 18:4 Comment(0)
L
-1

I had a similar problem when I used R8 on two of my libraries that obfuscated with the same name, throwing the duplicated error.

I used the @Keep annotation to avoid obfuscating public classes and interfaces, and it worked for me. I'm only obfuscating internal classes.

Example:

@Keep public interface MyInterface { ... }

Lepton answered 26/6, 2024 at 10:33 Comment(2)
thanks for the reply, I was am wondering how did you identify which interface it is?Beanpole
I had just one... but if you have several, add to all that are public to see if it fixes. Or add one by one until it fixes.Lepton

© 2022 - 2025 — McMap. All rights reserved.