How can I exclude external .jar from obfuscation by Proguard (Android project)? - android

When I export android project with proguard.cfg, all referenced .jar files are obfuscated as well. How can I exclude some of that .jars from obfuscation?

If you don't want to edit the Ant script, you can add -keep options to proguard.cfg for the classes in those external jars. For instance:
-keep class othercode.** { *; }
Or with a regular expression containing a negator:
-keep class !mycode.** { *; }
The standard Ant script will still merge all referenced jars in the single output jar though.

In your config file, set up your jars as library jars instead of input jars. This leaves them untouched.
-libjars <path/to/jars>

Using proguard maven plugin I do it like that
<inclusion>
<groupId>foo.bar</groupId>
<artifactId>foo-bar</artifactId>
<library>true</library>
<filter>!META-INF/**</filter>
</inclusion>
The
<library>true</library>
lead to the external jar merged into the final jar after the obfuscation. But this might lead to the Manifest being overwritten. I haven't figured out yet how to avoid that the best way.

Related

Proguard - how to keep all files a JAR uses?

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.

How to keep al external jar and class inside that jar in proguard

I have a android project which has many external jar reference.These jars are in libs folder so they get included but on launching app my application crashes on refering methods or fields of class(in external jar).To avoid this I write -keep class ** and then it works.
But as I have many jars so writing -keep for all is quite hectic.
I would also like to remove all the logs including verbose and all.Normal log have been removed by
-assumenosideeffects class android.util.Log {
*;
}
but still other logs like mediaplayer and setting and all coming.
is there any way around to this in proguard? How can i tell proguard to keep external jar with all the class and fields.?
Try insert
-libraryjars libs/android-support-v4.jar
and all libraries in file proguard.cfg

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

Using the Proguard tool with imported jars

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?

Problems compiling an Android App with Ant and Proguard

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

Categories

Resources