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 {
*;
}
Related
I am trying to build (release) an app and the app crashes due to the fact that there are generated methods that are being obfuscated by ProGuard. How can I ignore all of them in the release build?
I have tried to add the following in the proguard-rules.pro:
-keep public class !*Service_Impl.kt
but seems that it doesnt work. The classes that I want to ignore are named as
C1Service_Impl
C2Service_Impl
and so on and so forth, located in the generated java folder
com.application.myapp.persistence.services.C1Service
com.application.myapp.persistence.services.C2Service
Thanks in advance.
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.
I have written a java library that I don't want users to be able to see the source code. Hence I used proguard to obfuscated by java library into debug and release AAR. I'm trying to test the obfuscation in a demo project by importing it as an AAR file. When I import the release AAR file, everything is obfuscated and I'm not even able to resolve the symbols.
Is there any way I can obfuscate the source code but allow the AAR to be imported into another project? Similar to a static library/framework in iOS.
Thanks
You have to make sure to keep the class names and methods 'as is' for those classes that are accessed externally by apps using your library.
For example, to keep all public methods and variables declared by a class used by outside apps, add the following to your proguard-project.txt file:
-keep public class com.your.class {public *;}
See here for more information.
I have manually added a JAR to my project. It uses lots of classes with different prefixes and I can't search and add all of them to my proguard file.
Is there a way to keep all the file the jar uses? The jar is called nano-0.7.0.jar
Do you have a package name in your jar file? If you have, try -keep class yourpackageName.**{*;} to tell proguard system keep all the classes in your package, and then add -dontwarn yourpackageName.** to tell proguard system do not warning if the system can't find the class referenced by the class in your package.
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