Proguard: keepclassmembers inside a Namespace - java

I'm trying to obfuscate my Android app. After obfuscating, there are a few things broken, so I need to keep all classmembernames inside a special namespace.
what did't worked was
-keepclassmembers class my.namespace.to.keep** {*;}
any suggestion? It is no Problem if the whole class is kept or only its members.

You don't tell in what way it didn't work, but you may need to specify -keep instead of -keepclassmembers.
You can specify -printseeds to see which classes and class members are matched by the -keep options.

Related

How to keep java.lang.reflect when use proGuard

In my application I want use this library : https://github.com/xmuSistone/AndroidPileLayout
And I want use proguard in my project, when proguard my project show me may bugs.
For fix proguard, the library developer say:
proguard works wrong when you are using java.lang.reflect api, please
check your own code.
How can I fix it and keep java.lang.reflect?
Please help me
Reflection will need to have absolute path the the classes and its respective methods. So, you need to tell proguard to leave the stuff you need alone. You can describe this in your proguard-rules.pro file.
Example:
-keep public class fully_qualified_classname
-keepclassmembers public class fully_qualified_classname {
# will ignore all methods
public <methods>;
public static final String static_instance_variable_if_any;
}

Let ProGuard touch only one class

I am working on an app that someone else wrote and i am trying to only obfuscate the classes that I added. I've seen this post: With ProGuard, how do I obfuscate just one class?
I tried my luck with that (I added a single class and configured ProGuard as shown in the above post) and had only partial success.
It seems like ProGuard is still touching all the other files (md5 hashes change).
This is my ProGuard config:
-dontshrink
-dontoptimize
-dontpreverify
-dontnote
-dontwarn
-target 1.8
-keep class !com.example.Test { *; }
You should also try keeping all the other packages, like:
-keep class com.my.example.** { *; }
When you use a rule containing an exclusion pattern like that:
-keep class !com.example.Test { *; }
it will internally be treated like this:
-keep class !com.example.Test,** { *; }
The ** at the end is implicit and doesn't have to be added. Basically you are trying to say "keep all classes except com.example.Test" (and their methods/fields of course).

Can I keep all the contents in my jar file in just one sentence when I run proguard?

When I use proguard in android studio, I notice that there are -keep class mypakageName.**{*;} to keep the class in my package and -keep interface mypackageName.**{*;} to keep the interface in my package etc... but I find it is fussy, can't I keep all the files in my package in just one sentence? Or is there a method can do that?
Using -keep class will keep any java type, including classes, interfaces, enums.

Proguard warnings despite kept classes

I'm using Proguard to shrink my code. My strategy is to enable it and then follow the warnings to keep anything it complains about. If there are outside libraries, I try to follow the Proguard instructions the authors make available. Many instructions include a -dontwarn flag. If I disable the -dontwarn flag, I will get warnings. If we are keeping most classes via -keep flag, why do warnings still come up?
Example:
-keep class javax.** { *; }
# for butterknife
-keep class butterknife.** { *; }
-dontwarn butterknife.internal.**
-keep class **$$ViewBinder { *; }
-keepclasseswithmembernames class * {
#butterknife.* <fields>;
}
-keepclasseswithmembernames class * {
#butterknife.* <methods>;
}
Warning:butterknife.internal.ButterKnifeProcessor: can't find referenced class javax.annotation.processing.AbstractProcessor
Warning:butterknife.internal.ButterKnifeProcessor: can't find referenced class javax.annotation.processing.ProcessingEnvironment
Warning:butterknife.internal.ButterKnifeProcessor: can't find referenced class javax.lang.model.element.TypeElement
Warning:butterknife.internal.ButterKnifeProcessor: can't find referenced class javax.lang.model.element.Element
Warning:butterknife.internal.ButterKnifeProcessor: can't find referenced class javax.annotation.processing.Filer
Warning:butterknife.internal.ButterKnifeProcessor: can't find referenced class javax.tools.JavaFileObject
...
There are many warnings in ProGuard meaning different things. This particular one:
Warning:A: can't find referenced class B
Means that while ProGuard was processing class A it encountered reference to class B. But class B wasn't included as a source (-injars class_path) or as a library (-libraryjars class_path).
First note that for this particular warning in case of standard Android build chain adding -keep rules will not help. ProGuard transitively keeps referenced code.
This warning can happen for several reasons. Often a library X can contain code that uses another library Y. And X uses Y optionally - only when Y is present on the classpath, X doesn't enforce presence of Y. This way ProGuard is unable to find classes from Y.
To get rid of the warnings you have to either add Y as a dependency or ignore the relevant warnings.
In case of ButterKnife the situation is slightly different. Butterknife uses annotation processing. And it contains both the library and annotation processor in one dependency (latest version 7.0.1). So class butterknife.internal.ButterKnifeProcessor is still present in the compiled classes (even though it's work is already finished - used during java compilation). And ProGuard tries to process it. ProGuard fails to find the missing classes because they were used only during annotation processing and are not present for ProGuard processing.
In this case it's really necessary to ignore the warnings.

Android proguard Ignore All Classes except of one

I need help with turning off all features and disable everything that Proguard do for all classes but one. One class should be obfuscated (contains security things). Any ideas?
-dontshrink
-dontoptimize
-dontobfuscate
-keep,allowshrinking,allowoptimization,allowobfuscation class org.mypackage.MyClass
Use this Line into the proguard
Enter all package name for disable things of proguard
-dontwarn your_package_name.**

Categories

Resources