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).
Related
I have a Java application running on PC (Windows).
I use Netbeans.
I use Proguard to obfuscate the code and I configure the obfuscation by the build_common.xml (Ant) file; therefore the ProGuard configuration options are given by XML configuration tags.
I'm not expert at all of Xml, Proguard, I just copied and adapted some pieces of codes got in the web for my purposes and it worked.
Recently I introduced in my code ORMLite. When I run from IDE (so without obfuscation) my code works, but when I build with obfuscation it doesn't work.
Inside build_common.xml I excluded the "class com.j256.**" library, by:
<keep name="com.**" > <method name="*" /> <field name="*" /> </keep>
but it isn't enought because probably ORMLite uses special annotations.
I found out some post, suggesting to use for example:
-keepattributes *DatabaseField*
-keepattributes *DatabaseTable*
-keepattributes *SerializedName*
-keep class com.j256.**
-keepclassmembers class com.j256.** { *; }
-keep enum com.j256.**
-keepclassmembers enum com.j256.** { *; }
-keep interface com.j256.**
-keepclassmembers interface com.j256.** { *; }
-dontwarn com.j256.ormlite.logger.**
-dontwarn com.j256.ormlite.misc.**
but I don't know how to write those options in XML; I did some trying but it didn't work.
Can anybody help? Moreover on how to exclude from obfuscation ORMLite annotations.
Founded out the solution:
simply added inside the proguard tags of 'build_common.xml' file the line:
-keepattributes *Annotation*
`the rest of the lines mensioned in my question seems unusefull
I have tried out a lot of solutions on how to get this resolved. My debug works alright. But as at now, i am trying to build archive my apk in the release mode. When i re-build in the release mode i get the error Java exited with code 1 (MSB6006).
Proguard and multi-dex is enabled in my Droid project. My heap size is also set already to 1G. I also created a proguard.cfg file in my Droid project but i still get the same error. When i check the error reference, it leads to me this in my browser MSBuild.ToolTask.ToolCommandFailed.
Is there any other i could solve this ?
Attached is the https://gist.github.com/anonymous/9e7fba8cc745ce9ae06fa2c8ae075697 - Full Diagnostic Build Output.
proguard.cfg
# This is Xamarin-specific (and enhanced) configuration.
-dontobfuscate
-keep class mono.MonoRuntimeProvider { *; <init>(...); }
-keep class mono.MonoPackageManager { *; <init>(...); }
-keep class mono.MonoPackageManager_Resources { *; <init>(...); }
-keep class mono.android.** { *; <init>(...); }
-keep class mono.java.** { *; <init>(...); }
-keep class mono.javax.** { *; <init>(...); }
-keep class opentk.platform.android.AndroidGameView { *; <init>(...); }
-keep class opentk.GameViewBase { *; <init>(...); }
-keep class opentk_1_0.platform.android.AndroidGameView { *; <init>(...); }
-keep class opentk_1_0.GameViewBase { *; <init>(...); }
-keep class android.runtime.** { <init>(***); }
-keep class assembly_mono_android.android.runtime.** { <init>(***); }
# hash for android.runtime and assembly_mono_android.android.runtime.
-keep class md52ce486a14f4bcd95899665e9d932190b.** { *; <init>(...); }
-keepclassmembers class md52ce486a14f4bcd95899665e9d932190b.** { *; <init>(...); }
# Android's template misses fluent setters...
-keepclassmembers class * extends android.view.View {
*** set*(***);
}
# also misses those inflated custom layout stuff from xml...
-keepclassmembers class * extends android.view.View {
<init>(android.content.Context,android.util.AttributeSet);
<init>(android.content.Context,android.util.AttributeSet,int);
}
Turn on MultiDex
RightClick on Xamarin.Android--->Goto Properties-->AndroidOptions-->Now Enable MultiDex
Now Clean and Rebuild your solution
We had similar issues and nailed it down to our app going over 65k methods limit (which could be what's happening when you reference google play services).
https://developer.android.com/studio/build/multidex.html
The below link useful for you
https://forums.xamarin.com/discussion/44381/project-wont-build-keeps-failing-with-error-message-java-exe-has-exited-with-code-2
ProGuard and MultiDex on Xamarin.Android need a little extra work.
Related to ProGuard, it may be removing some Java classes from your APK and causing bugs. You need to create a proguard.cfg file and set its Build Action to ProguardConfiguration. By the way, it is not necessary to set the Heap size to 1G.
Related to MultiDex, you also need to create a MultiDexApplication class that extends Application.
If you are using the Android SDK for Windows, you need to update proguard.jar to its latest version and also change mainClassesDex.bat.
I'm trying to get ProGuard to work, after roughly 4 hours of randomly trying options to try and get this amazing software to work.
My project is using LibGDX and KryoNet. This is my current ProGuard configuration:
-verbose
-dontobfuscate
-dontwarn android.support.**
-dontwarn com.badlogic.gdx.backends.android.AndroidFragmentApplication
-dontwarn com.badlogic.gdx.utils.GdxBuild
-dontwarn com.badlogic.gdx.jnigen.BuildTarget*
-dontwarn com.badlogic.gdx.graphics.g2d.freetype.FreetypeBuild
-keepclassmembers class com.badlogic.gdx.backends.android.AndroidInput* {
<init>(com.badlogic.gdx.Application, android.content.Context, java.lang.Object, com.badlogic.gdx.backends.android.AndroidApplicationConfiguration);
}
# Kryo
-dontwarn sun.reflect.**
-dontwarn java.beans.**
-dontwarn sun.nio.ch.**
-dontwarn sun.misc.**
-keep class com.esotericsoftware.kryo.** {*;}
-keep class com.esotericsoftware.** {*;}
-keep class java.beans.** { *; }
-keep class sun.reflect.** { *; }
-keep class sun.nio.ch.** { *; }
This does not compile. It throws multiple of the following errors: Uncaught translation error: com.android.dx.cf.code.SimException: local variable type mismatch: attempt to set or access a value of type float using a local variable of type int. This is symptomatic of .class transformation tools that ignore local variable information.
I found some information about this error: Compile with Proguard gives SimException: "local variable type mismatch".
The solution given was to edit some main-rules.xml file from ANT, but I'm using Gradle. A comment was posted with a fix for Gradle : to add project.tasks.withType(com.android.build.gradle.tasks.Dex) { additionalParameters=['--no-locals'] }. But apparently the Dex class is removed, so this no longer works.
I read this is a bug in ProGuard, and that obfuscating should fix it. But when I remove the -dontobfuscate line, my app does not start anymore: java.lang.UnsatisfiedLinkError: No implementation found for void com.a.a.c.a.k.g() (tried Java_com_a_a_c_a_k_g and Java_com_a_a_c_a_k_g__).
Does anyone know how to work around these issues?
The problem might be related to a specific optimization of ProGuard.
You can disable it like that:
-optimizations !code/allocation/variable
Furthermore you can also remove the LocalVariableTable and LocalVariableTypeTable attributes which do not seem to be updated properly (and are not needed in an application anymore). For this you would need to enable obfuscation though and then use something like:
-keepattributes !LocalVariable*,**
This rule would keep all attributes but the LocalVariable related ones.
The obfuscation problem with libGDX might be solved by this rule:
# Keep names - Native method names. Keep all native class/method names.
-keepclasseswithmembers,includedescriptorclasses class * {
native <methods>;
}
I tested ProGuard on a simple application. It works very well. However, when i tried to use it on something more complex, it thows all types of warnings and error like one class depends on other or a class tries to use reflection etc.
This is the configuration
-injars Test.jar
-outjars Test2.jar
-libraryjars <java.home>/lib/rt.jar
-libraryjars <java.home>/lib/jce.jar
-printmapping myapplication.map
-keep class com.teradata.** {*;}
-keep class org.quartz.** {*;}
-keep class org.terracotta.** {*;}
-keep class com.sun.** {*;}
-keep class javax.** {*;}
-keep class org.apache.** {*;}
-keep class org.slf4j.** {*;}
-keep class com.** {*;}
-keep public class com.test.Main {
public static void main(java.lang.String[]);
}
Is there any simple way to make it work. If something should be in -keep, can it automatically do so? Process as much as it can, and leave the rest .
I also tried the gui version . But I couldn't figure out how to -keep the jars.
Also it's too verbose even without the verbose keyword . I can't get to the root of the problem because of enormous number of the duplicate error message like Maybe blah blah and then the same thing again and again .
Is there any simple way to just make it work ?
If you do not want to be bothered by looking at the warnings and fix them appropriately (or use -dontwarn directives to ignore harmless ones), you can use the -ignorewarnings directive, which will instruct ProGuard to keep processing your application even if there are some warnings remaining.
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.