Android proguard rules - android

Just wondering what exactly this means.
-keep class !com.my.package.** { *; }
Does it mean not obfuscate anything. Does it defeat the purpose of using proguard?

It will obfuscate your package classes including sub-packages and classes in them.
Why not if the app doesn't use any external library :)

Related

Proguard: Keep classes in a certain package

I have some classes which are used via reflection. It appears ProGuard is removing these when I build for release.
Is there any way to specify that all the classes in a particular package (as opposed to the specific class names) to not be removed when ProGuard runs. As a note, obfuscation is wanted. As another note, all these classes extend a single class which is present.
Thanks
Using -keep class com.yourpackage.name.** { *; } works well in my case. It essentially uses the wildcard to keep all classes belonging to that package. Also note the *; is required.
Also, to help debug your issue, you should check the generated seeds.txt, if the class is included then its kept.
Moreover it could be another issue like using public static inner classes or so. The best way to debug would be to decompile the minified apk using dex2jar and JD-GUI and manually skim through the code to see what's being stripped or kept. Don't forget to -dontdeobfuscate before.
Have you tried to add this line in your proguard-rules.pro file?
-keep class com.company.application.PackagePrefix*
{
*;
}
If you don't want to use package prefix you can use ** instead.
Hope it helps.

Proguard configuration for sqlite android bindings

I am trying to use SQLite android bindings to have a custom encrypted SQLite DB in my android app. It all works fine and I am about to publish my app. I am trying to use ProGuard for code obfuscation and compression but does not seem to work fine with SQLite android bindings. My released app crashes on startup because it cannot find few .so files used by SQLite. I am not sure what should be the correct ProGuard rule to keep those libraries.
Right now I have added only this to my ProGuard:
-keep class org.sqlite.**
Usually,
-keep class org.sqlite.** { *; }
-keep class org.sqlite.database.** { *; }
would do the trick.
Verify your mapping.txt for what ProGuard is already done, and make sure that your models are not got renamed. If so, you may need
-keep class com.your.modelspackage.**
-keepclassmembers com.your.modelspackage.** { *; }
Hope it helps

Android proguard crashes after enabling google analytics

I activated google analytics for my android application, when I tried to use proguard I got this errors.
What is the solution?
It means that class is obfuscated by proguard.
Personally I always add the generic rule
-keep class com.google.** { *; }
in my proguard because I only care for obfuscation of my own code. That should fix your error. But if you just want to add that class only it should also work I guess.

Including external libraries in Android Proguard

My app is able to run without any issues during testing etc. But when I export out apk compiled with ProGuard, there are issues like random crashing and some features not working as expected.
I not sure is it due to the external jar libraries I have included in the project which is not properly configured in Proguard.
I have included the following in the proguard-android.txt file. I have two libraries so I added these:
-keep class org.apache.commons.net.** { *; }
-keep class org.jsoup.** { *; }
Is it the correct way? Is there any other way?
To add libraries just add -libraryjars ../libs/<libname>
After that you may need to keep classes and interfaces based on the errors you receive

is it possible to obfuscate part of classes/packages in apk?

I have developed one android application which is having set of activities,background service and some other utility packages(which are written on pure java), i don't want to obfuscate activities and background service but need to obfuscate utility packages(pure java code), is it possible to do so?if yes then how to enable it in my proguard.cfg file?
OR in more precise way:
Application is using some external jars which are added to project's lib folder, I want only these jars should get obfuscated and rest of application code(activities , service etc...) should not get obfuscated. How to achieve the same using eclipse and proguard.cfg?
Regards,
Piks
If proguard is activated then Android will automatically include the used library files when creating a signed APK in Eclipse, so you don't have to specify this.
If the package name of your application is different from the package names of your libraries then you can simply use a wildcard and add this to your proguard.cfg file
-keepnames class com.mypackagename.** {
*;
}
If the packagename is the same, then you'll have to specify which classes should be obfuscated by hand, e.g.
-keepnames class com.mypackagename.MyApp {
*;
}
-keepnames class com.mypackagename.subpackage.MyClass {
*;
}

Categories

Resources