3

I'm trying to obfuscate my package names including that one of my used libraries.

I use this build config in my gradle file:

buildTypes {
    debug {
        versionNameSuffix "-Development"
        debuggable true
        runProguard true
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
    #...

This is my proguard file:

# Butterknife
-dontwarn butterknife.internal.**
-keep class **$$ViewInjector { *; }
-keepnames class * { @butterknife.InjectView *;}

# OrmLite uses reflection
-keepclassmembers class com.j256.** { *; }
-keep class my.package.name.database.** { *; }
-keep class com.j256.**

#test
-repackageclasses 'qqq1'
-flattenpackagehierarchy 'qqq2'
-allowaccessmodification
-forceprocessing

I'm using this command for dumping all the dexed classes:

7z x -aoa my.apk classes.dex && dexdump classes.dex | grep "Class desc" | less

And I still see all full package names if I just grep for "qqq" I get no results so it seems that both rules repackageclasses and flattenpackagehierarchy seems to be ignored (I also tested to use only one of that lines). Any idea what I missed?

rekire
  • 47,260
  • 30
  • 167
  • 264
  • (i deleted my original question and reformulated it a litte bit): can you show us the source of one minimal example class that you find in the dump and you would expect that its package should be changed to qqq1 or qqq2? – k3b Jun 26 '14 at 07:50
  • It's too simple so that I won't edit my question. E.g. a simple class like a view holder that just contains some references without extending View or Activity, etc. That class should been renamed from `com.example.android.utils.ViewHolderExample` to `qqq1.A` and finally just to `A` if I replace 'qqq1' with '' and just in case that for some restrictions that is not possible even `a.b.c.d.A` would be fine, the only thing I expect is that there is no more trace of "com.example". – rekire Jun 26 '14 at 08:00
  • 1
    Some classes can't be obfuscated because their names are specified in the AndroidManifest.xml (e.g. activities). – Robert Apr 30 '15 at 12:02

2 Answers2

1

For library modules, it seems that the build system add "-keeppackagenames" by default which will lead to the package names not be obfuscated.

You can try using this WORKAROUND:

Add "-keeppackagenames !**" to disable -keeppackagenames being injected by the build system.

Via: https://code.google.com/p/android/issues/detail?id=67587

Alan Zhiliang Feng
  • 1,774
  • 18
  • 20
1

Wow this took long to fix. The butterknife rules broke everything. My solution was to grep that one from the homepage and how everything works as expected.

Here are the fixed rules:

# Butterknife
-keep class butterknife.** { *; }
-dontwarn butterknife.internal.**
-keep class **$$ViewBinder { *; }

-keepclasseswithmembernames class * {
    @butterknife.* <fields>;
}

-keepclasseswithmembernames class * {
    @butterknife.* <methods>;
}

# OrmLite uses reflection
-keepclassmembers class com.j256.** { *; }
-keep class my.package.name.database.** { *; }
-keep class com.j256.**

#test
-repackageclasses 'qqq1'
-flattenpackagehierarchy 'qqq2'
-allowaccessmodification
-forceprocessing
rekire
  • 47,260
  • 30
  • 167
  • 264