Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Library Project: Obfuscate and keep resources

I want to compile with Proguard my Android project with some additional Android Library Projects. In fact, most of code and resources lie in these libraries.

I've added line "proguard.config=proguard.cfg" into project.properties of main project, I've configured cfg-file (-libraryjars ..\libs). Then - right click, Android Tools -> Export Signed Application Package. ADT compiled project for release but app crashed at the first launch: as I read from log, it was because of wrong resource pointer.

I've decompiled project and found out very strange thing: if I declare resource in the library, then resource pointer on it becomes 0.

Problem didn't disappear when I add line "proguard.config=proguard.cfg" into project.properties of all of my Android Library Project.

Any solutions?

Edit: look at fragment of proguard.cfg:

-optimizationpasses 5
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontpreverify
-verbose
-optimizations !

-printusage unused.txt
-optimizationpasses 2
-printmapping mapping.txt
# -overloadaggressively
-dontusemixedcaseclassnames
-dontskipnonpubliclibraryclasses
-dontpreverify
-verbose
-dump class_files.txt
-printseeds seeds.txt

-libraryjars ..\libs
like image 583
QuickNick Avatar asked Feb 10 '12 14:02

QuickNick


People also ask

How do I obfuscate an Android library project?

In order to obfuscate your library what you need to do is: Make sure gradle settings for lib module state minifyEnabled true . run ./gradlew assemble{flavor}Release.

Does ProGuard remove unused resources?

The ProGuard tool shrinks, optimizes, and obfuscates your code by removing unused code and renaming classes, fields, and methods with semantically obscure names. The result is a smaller sized . apk file that is more difficult to reverse engineer. You can easily search for unused resources from Android Studio.

What is the difference between ProGuard and R8?

R8 has more Kotlin support than that of Proguard. R8 is having a faster processing time than Proguard which reduces build time. R8 gives better output results than Proguard. R8 reduces the app size by 10 % whereas Proguard reduces app size by 8.5 %.


1 Answers

Are you sure you have the latest tools? Like Eclipse Indigo, ADT v16.0.1 and proguard 4.7? I also had issues before updating to the latest tools.

like image 68
pandre Avatar answered Oct 01 '22 18:10

pandre