ProGuard - Obfuscate and Shrink "app" module only? - android

I am trying to use ProGuard first time to obfuscate only "app" module of my project. But i either face problems generating apk or the generated apk simply crash the app.
I have already tried following ProGuard rule:
-keep class !com.example.mypackage.**{ *; }
But it generates following error:
Warning:library class android.content.res.XmlResourceParser extends or
implements program class org.xmlpull.v1.XmlPullParser
So i want to know if i can just obfuscate and shrink only single module without using any other functionality.

The rule itself will not create this warning. It looks like you included something as compile dependency that contains the XmlPullParser class which is already present in the Android SDK jar.
This warnings is usually harmless and can be ignored by adding -ignorewarnings to your ProGuard configuration, but I would check all your dependencies and investigate where this class is included from.

Related

How can I import Proguard obfuscated module into Android Studio?

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.

Conflict between Android data binding and Guava causes ProGuard error

I get the following error while compiling my Android app with ProGuard enabled.
Warning: library class android.databinding.tool.util.SourceCodeEscapers$1
extends or implements program class com.google.common.escape.CharEscaper
Warning: library class android.databinding.tool.util.SourceCodeEscapers$JavaCharEscaper
extends or implements program class com.google.common.escape.ArrayBasedCharEscaper
Warning: library class android.databinding.tool.util.SourceCodeEscapers$JavaCharEscaperWithOctal
extends or implements program class com.google.common.escape.ArrayBasedCharEscaper
Warning: there were 3 instances of library classes depending on program classes.
You must avoid such dependencies, since the program classes will
be processed, while the library classes will remain unchanged.
(http://proguard.sourceforge.net/manual/troubleshooting.html#dependency)
It appears that this is caused by a conflict between Android data binding and Guava. My app depends on Guava (com.google.guava:guava:18.0) and has data binding enabled. It appears that data binding has some sort of internal dependency on Guava and that is causing a problem with ProGuard.
I am running the latest beta version of gradle (2.0.0-beta5) so perhaps the problem is related to that.
So I was able to Build by adding this to proguard:
-dontwarn android.databinding.**
-keep class android.databinding.** { *; }
Which I don't think is entirely the right solution to just ignore those classes but I think we might just have to wait for an update from Google. After adding that to proguard I was able to build a release apk but it was crashing, I thought it was still proguard but found other errors in my code.

Android ProGuard obfuscation of library: keep class not working

Intro: I have in AS 1 project with 2 models:
Android library project with some "Public API class"
Android APP dependent on above library (the library module is on the dependency list)
Task: I want to obfuscate my library project because I want to expose it as public SDK but keep my code protected...
What I did: So I made custom ProGuard rules:
-dontshrink
-dontoptimize
-dontpreverify
-keep class com.org.my_public_api_class_name
I skip all other stages in order to eliminate where the bug is to only obfuscation stage.
Result: Build of the APP module fails with errors like
Error: cannot find symbol class my_public_api_class_name
It seems for me that the problem is that the obfuscation NOT skipped the class I wanted to, so now he has some meaningless name and therefore in the APP, where I'm using him, The original name not exist.
Thanks,
To exclude your class from obfuscation, try this:
-keep class com.org.my_public_api_class_name**
-keepclassmembers class com.org.my_public_api_class_name** {*;}

Unknown classes ILicensingService notes when obfuscating Android project

I'm trying to build an Android release with Ant and ProGuard. I uncommented the following line in project.properties, despite the comment in said file noting that you shouldn't modify it ;):
proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
When obfuscating, I get the following notes:
[proguard] Note: the configuration refers to the unknown class 'com.google.vending.licensing.ILicensingService'
[proguard] Note: the configuration refers to the unknown class 'com.android.vending.licensing.ILicensingService'
I do understand why this is happening. These lines can be found in the default ProGuard config file (${sdk.dir}/tools/proguard/proguard-android.txt):
-keep public class com.google.vending.licensing.ILicensingService
-keep public class com.android.vending.licensing.ILicensingService
I'm not using the Google Licensing Service, so the classes are indeed unknown. I found a solution to get rid of these notes by updating the proguard-project.txt:
-dontnote **ILicensingService
My question: Is this the correct way of handling this? It seems to me that these classes shouldn't be kept by default anyway, since that lib isn't mandatory for an android project. The only way I can think of to achieve this is by copying the default config file to my project, removing the -keep lines and ignoring the default config file in the SDK completely. Which doesn't seem as the proper way to go either. Or am I missing something?
The setting "-dontnote com.google.vending.licensing.ILicensingService" is fine. In fact, it could have been part of the default configuration file.
The -keep option may be necessary for projects that use the library.
The -dontnote option may be nice to suppress the note about the -keep option, for projects that don't use the library. The note is just a gentle reminder that the configuration file could contain a typo, because the specified class doesn't seem to exist. It doesn't affect the processing.

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