I am developing SDK, my environment got SDK library and a testing project that use it.
I want to protect my library code from my library users and there for I need to obfuscate it, but just it.
So in Android Studio in my library Module, in proguard-rules.pro file I added the next script:
-dontpreverify
-optimizations !code/simplification/arithmetic
-keep class !com.example.**{ *; }
-keep public class com.example.sdk.Example{*;}
-keep public class com.example.sdk.IExampleCallback{*;}
-keep public class com.example.sdk.ui.ExampleActivity
-dontwarn android.util.Log
-repackageclasses 'com.example.security'
-allowaccessmodification
The classes get obfuscated but their package is not changed. I fallowed Eric Lafortune(The author of Proguard) suggestion to add allowaccessmodification
, but it didn't helped. I also try using flattenpackagehierarchy
, but it had no effect.
Help me, how to place all my classes in one package?
Solved it: After adding those lines it did the job
-useuniqueclassmembernames
-keeppackagenames doNotKeepAThing
This is my full script
-optimizationpasses 30
-mergeinterfacesaggressively
-dontpreverify
-optimizations !code/simplification/arithmetic
-repackageclasses 'com.example'
-allowaccessmodification
-useuniqueclassmembernames
-keeppackagenames doNotKeepAThing
-keep class !com.example.**{ *; }
-keep public class com.sdk.example{
*;
}
-keep public class com.sdk.IExampleCallback{
*;
}
-keepclasseswithmembernames public class com.sdk.ui.activity.ExampleActivity{
public <methods>;
protected <methods>;
}
-keepclasseswithmembernames public class com.example.sdk.ExampleReciever{
public <methods>;
}
-assumenosideeffects class android.util.Log {
public static boolean isLoggable(java.lang.String, int);
public static int v(...);
public static int i(...);
public static int w(...);
public static int d(...);
public static int e(...);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With