facebook / redex

A bytecode optimizer for Android apps
https://fbredex.com/
MIT License
6.03k stars 653 forks source link

Found duplicate class(classes from android.jar) in two different files #861

Closed pidanxiangjiao closed 5 months ago

pidanxiangjiao commented 5 months ago

When i process our apk file, i got below error:

libc++abi: terminating with uncaught exception of type RedexException: RedexError: 4 with message: 
Found duplicate class in two different files. with extra info: ("class", "Landroid/app/ServiceStartNotAllowedException;")
 ("dex", "xxx/xxx/tmpi3y92g6y.redex_dexen/dex0/classes.dex") 

We use redex after r8 procession. And the r8 team says:

these classes are synthesized by D8/R8 in order to improve app performance by mitigating soft verification errors. You can read more about this in [this blog post](https://medium.com/androiddevelopers/mitigating-soft-verification-issues-in-r8-and-d8-7e9e06827dfd).these classes are synthesized by D8/R8 in order to improve app performance by mitigating soft verification errors. You can read more about this in [this blog post](https://medium.com/androiddevelopers/mitigating-soft-verification-issues-in-r8-and-d8-7e9e06827dfd).these classes are synthesized by D8/R8 in order to improve app performance by mitigating soft verification errors. You can read more about this in [this blog post](https://medium.com/androiddevelopers/mitigating-soft-verification-issues-in-r8-and-d8-7e9e06827dfd).

Is there any configuration to skip such error ? or would you mind give some suggestion to fix it?

currently i am thinking about don't use r8 and just use d8 to generate dex and then process dex files with redex. then finally use r8 do obfuscation.

wsanville commented 5 months ago

Redex does not gracefully handle the stubs that R8 produces, though you should be able to turn off the stubbing feature/API modeling feature of R8 with System.setProperty("com.android.tools.r8.disableApiModeling", "1") in your gradle file. That's the recommendation for now. At some point we will handle the stub classes properly but I cannot give any ETA for this.

See also https://r8.googlesource.com/r8/+/2a95f30bbbcf0c10d49272b51a2a331ba8730843/src/main/java/com/android/tools/r8/utils/InternalOptions.java#2028

agampe commented 5 months ago

currently i am thinking about don't use r8 and just use d8 to generate dex and then process dex files with redex. then finally use r8 do obfuscation.

One thing to note: Redex can obfuscate perfectly fine. You wouldn't need the r8 step.