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.
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 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.
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 {
*;
}
I'm using a jar of which I don't have the source code. I started using the proguard tool and some of the functionality of the implementation of this jar stop working, so I tried changing the proguard configuration by adding (As seen in another question):
-keep class com.myexternaljar.** { public protected *; }
But it still doesn't behave as it should. So I'm guessing that this jar uses some other external classes that are being modified by the proguard tool.
Is there any configuration that can keep all the classes in a certain jar and all the classes that aren't in the jar itself but that are used by it?
I have an Android App which consists on different modules. The Main module is using some libs like Google's GSON or the v4.support.package. A custom build script with the right proguard.cfg will build it, too.
Now I must integrate another "Android-Library" which uses partly the same libs (GSON support.v4). Beside from getting a lot of Notes like
Note: duplicate definition of program class [com.google.gson.Gson]
I get also some Notes like
[proguard] Note: com.google.gson.UnsafeAllocator: can't find dynamically referenced class sun.misc.Unsafe
[proguard] Note: the configuration refers to the unknown class 'sun.misc.Unsafe'
that I find strange cause i have some 'keeps' in my Proguard.cfg especially for that:
-keepattributes Signature, Annotation
-keep class com.google.gson.** {*;}
-keep class sun.misc.Unsafe { *; }
which works well on my project without referencing the module-library inside it.
I'm on the Latest SDK and Tools, and added a custom proguard.cfg to the module-library, which works well on the module-lib itself (if build in standalone-mode).
It seems to me, that the build is not depending on custom proguard.cfg inside library-projects. Any idea on what to try highly appreciated
I finally found a solution for it myself:
with the last Android Tools (16), every Android-Library gets compiled on its own first.
So when the lib has not a "standart" build and defines some custom build script including proguard --keeps, and this --keeps are defined on the same Project (excluding Android SDK classes, as thei're not compiled) it leads to an proguard error.
The Solution was do remove proguard out of the lib and copy the --keeps inside the main App