Reputation: 7283
I'm writing 2 Android libraries. When I obfuscate both, the obfuscated code in both of them contains a class named a.a.a.a.a
which causes the following error when trying to use both libraries in the same application:
Duplicate class a.a.a.a.a found in modules classes.jar (lib1) and classes.jar (lib2)
How can I prevent Proguard
from obfuscating the first 3 packages to end up with:
my.domain.lib1.a.a
and my.domain.lib2.a.a
?
Edit: The obfuscation is happening as part of building the libraries, not while building the application.
Upvotes: 6
Views: 1839
Reputation: 63
Add the code below to the proguard-rules.pro
file.
-keeppackagenames
Upvotes: 0
Reputation: 7283
This can be resolved by putting -repackageclasses my.domain.lib#.ofs
in the proguard-rules
file of each library while replaceing #
with 1
and 2
respectivly. This will move all the obfuscated classes into the my.domain.lib#.ofs
package while all the non-obfuscated classes will remain in their original packages and you're guaranteed to have no collisions.
As the Proguard
documentation states:
-repackageclasses [package_name]
Specifies to repackage all class files that are renamed, by moving them into the single given package.
Another solution is to use -keeppackagenames
. Unfortunately, I couldn't find a way to make it keep only the first 3 packages.
See the Proguard
documentation:
-keeppackagenames [package_filter]
Specifies not to obfuscate the given package names.
Upvotes: 2