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.
Related
I have been trying to fix this problem for a week now. I create a shadowJar (uber jar) and it starts fine. When I run obfuscation, I get an error on startup:
Caused by: java.lang.UnsatisfiedLinkError: Can't obtain peer field ID for class com.sun.jna.Pointer
I have been using Proguard to run obfuscation and I always get this after the process
"Note: com.sun.jna.Structure accesses a constructor '(com.sun.jna.Pointer)' dynamically"
Here is a snippet of my .pro file:
-dontshrink
-dontoptimize
-keepattributes Exceptions,InnerClasses,Signature,Deprecated,SourceFile,LineNumberTable,LocalVariable*Table,*Annotation*,Synthetic,EnclosingMethod
-keep class com.sun.jna.** {
<fields>;
<methods>;
}
-keep,allowshrinking class com.sun.jna.** {
<fields>;
<methods>;
}
Am I doing it wrong or missing something important? I am assuming the message after processing is related to the start-up error I have from the obfuscated jar.
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).
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.
Trying to obfuscate using ProGuard but getting 3rd party libraries errors, so I'm excluding each package one by one:
-keepclassmembers class android.** {*;}
-keepclassmembers interface android.** {*;}
-keepclassmembers class com.google.** {*;}
-keepclassmembers interface com.google.** {*;}
Is there a way to whitelist only my package name?
com.dht.github.myApp
According to your code you are just keeping class members not whole class.
Use this to keep class as it is.
-keep class com.google.** {*;}
-keep interface com.google.** {*;}
You also can use this line to only obfuscate your own classes and keep everything else.
-keep class !com.yourpackage.**,!com.youranotherpackage.** { *; }