Android build fails with kotlin-reflect and proguard - android

I am unable to build my release product if I include kotlin-reflect with it. I attempted adding this to proguard configuration:
-keep class kotlin.reflect.** { *; }
But it did not help at all. Here is the error result from the gradle build:
Optimizing...
Unexpected error while performing partial evaluation:
Class = [kotlin/reflect/jvm/internal/impl/renderer/DescriptorRendererImpl]
Method = [renderPossiblyInnerType(Ljava/lang/StringBuilder;Lkotlin/reflect/jvm/internal/impl/descriptors/PossiblyInnerType;)V]
Exception = [java.lang.IllegalArgumentException] (Stacks have different current sizes [0] and [1])
Warning: Exception while processing task java.io.IOException: java.lang.IllegalArgumentException: Stacks have different current sizes [0] and [1]
I am using kotlin 1.1.1 (and gradle 3.3, if that matters.)
j

I had some similar errors with kotlin reflect class and proguard, solved adding in the -optimizations
!class/unboxing/enum
My bug was related to this Android Proguard failing with "Value 'i' is not a reference value"
and found the fix in one of the comments

Related

Proguard Overflow of unsigned short value

After adding a jar file containing some functionality that I need to my application, my proguard build hasn't been working. the error message I get after running my proguard build is:
Warning: Exception while processing task java.io.IOException: java.lang.RuntimeException: Unexpected error while writing class [proguard/optimize/gson/_OptimizedTypeAdapterFactory] (Overflow of unsigned short value [93362])
Thread(Tasks limiter_1): destruction
Is there any way to exclude that jar file from being checked by ProGuard? I'm using ProGuard v6.2.2. I suspected the issue would be GSON since i had issues with it before this error.
I've also checked and researched answers here such as Proguard [ java.lang.IllegalArgumentException: Overflow of unsigned short value ]
Android crash while using GSON Library and ProGuard
#732 Exception while handling very long string argument
Any help would be appreciated.
You can read more about ProGuard configuration and optimizations here:
https://www.guardsquare.com/en/products/proguard/manual/usage/optimizations
but in your case you can exclude the gson library that is throwing the exception like this:
-optimizations !library/gson
That's a known bug. Until this had been rectified, you can only disable the code optimization:
-optimizations !code/simplification/string
Or disable optimization altogether with -dontoptimize. Or just use R8 instead ...
That one linked answer which suggests a version-downgrade might also work.

Proguard keep fails about excluded .jar class

I made a simple app with external .jar library.
And going to obfuscator work with ProGuard.
But stuck with errors even had proguard rules.
I don't even know "borken class file" meaning about....
Can anyone know about this problem? Thanks. (Setting options or config attached as bottom section)
# Messages at Android Studio
Error processing C:\Users\administator\Desktop\artest\app\src\main\libs\arsupport.jar:ac.class: broken class file?
Error processing C:\Users\administator\Desktop\artest\app\src\main\libs\arsupport.jar:am.class: broken class file?
...
...
More similar errors...
...
...
Error:Execution failed for task ':app:transformClassesAndResourcesWithProguardForRelease'.
> java.io.IOException: Can't read [C:\Users\administrator\Desktop\artest\app\src\main\libs\arsupport.jar(;;;;;;**/*.class)]
(Can't process class [com/arsec/Programsupport.class] (Unknown verification type [46] in stack map frame))
and ProGuard rules
# proguard-rules.pro
-keep class com.arsec.** { *; }
-keep interface com.arsec.** { *; }
-dontwarn com.arsec.**
I got the same issue in my project,some suggest to reset the value ATTR_StacjMapTable to "dummy" in ClassConstants.java .then repack the proguard.jar
But I solve the problem is get the latest ProGuard in [http://proguard.sourceforge.net the use the latest proguard to make jar. goodlucky

Android Proguard failing with "Value 'i' is not a reference value"

I recently added a library to my app ('GNSDK' by Gracenote) and am now trying to build the app for release using Proguard. I successfully built and installed the release version of the app once, but all subsequent attempts produce this error:
Unexpected error while evaluating instruction:
Class = [com/gracenote/gnsdk/GnManager]
Method = [<init>(Landroid/content/Context;Ljava/lang/String;I)V]
Instruction = [87] getfield #120
Exception = [java.lang.IllegalArgumentException] (Value "i" is not a
reference value [proguard.evaluation.value.UnknownIntegerValue])
Unexpected error while performing partial evaluation:
Class = [com/gracenote/gnsdk/GnManager]
Method = [<init>(Landroid/content/Context;Ljava/lang/String;I)V]
Exception = [java.lang.IllegalArgumentException] (Value "i" is not a reference value [proguard.evaluation.value.UnknownIntegerValue])
:app:proguardBetaRelease FAILED
Error:Execution failed for task ':app:proguardBetaRelease'.
Value "i" is not a reference value [proguard.evaluation.value.UnknownIntegerValue]`
I tried to force proguard to leave the library alone (since that's the only difference between the debug and release builds) with:
-keep class com.gracenote.** {
*;
}
but it does not seem to make a difference.
Any hints on how to debug or track down this error? I am not sure why the constructor of com.gracenote.gnsdk.GnManager would be failing. The error makes it sound like it is getting an invalid input.
I'm using Android Studio 1.4, build tools 23.0.0.
I found that this is a bug in Proguard: https://sourceforge.net/p/proguard/bugs/573/
Looks like it will be released soon. In the meantime, you can work around by adding:
-optimizations !class/unboxing/enum
to your proguard file.
For what it's worth, I found this for a java project. I was running proguard targeting 1.8 when it should have been 1.9. Once I changed it it worked.

Conversion To Dalvik format Exception : Invalid dex bytecode offset

I am getting the following error when trying to run my code with ADT v21 using Eclipse Juno.
[2013-05-28 10:08:39 - XYZ] Dx
EXCEPTION FROM SIMULATION:
[2013-05-28 10:08:39 - XYZ] Dx local 000c: invalid
[2013-05-28 10:08:39 - XYZ] Dx ...at bytecode offset 00000c80
locals[0000]: Lcom/sec/x/y/z;
locals[0001]: I
locals[0002]: I
locals[0003]: Landroid/content/Intent;
locals[0004]: Ljava/lang/String;
locals[0005]: invalid
locals[0006]: Ljava/lang/String;
locals[0007]: invalid
locals[0008]: invalid
locals[0009]: invalid
locals[000a]: invalid
locals[000b]: Ljava/lang/String;
locals[000c]: invalid
locals[000d]: invalid
locals[000e]: invalid
locals[000f]: invalid
locals[0010]: invalid
locals[0011]: invalid
...while working on block 0c80
...while working on method onActivityResult IILandroid/content/Intent V
...while processing onActivityResult (IILandroid/content/Intent V
...while processing com/sec/x/y/z.class
[2013-05-28 10:09:05 - XYZ] Dx 1 error; aborting
[2013-05-28 10:09:05 - XYZ] Conversion to Dalvik format failed with error 1
This project builds perfectly on ADT v20 and below. But it is consistently giving the same error with ADT v21. The error does not occur in build stage. It occurs when I try to run the application using Eclipse.
I have read thousands of threads related to this. And none of them are working. This is not a "Clean/Build" issue for sure.
To me it seems like an Eclipse or Proguard issue. I have wasted alomst 12 hours of my life on this. Please somebody save me. Anyone with any clue on this?
"locals invalid ... Conversion to Dalvik format failed with error 1" may be caused by ProGuard's optimization step, which can't always keep the debug information about local variables consistent with the optimizations on the code.
You can avoid it by not keeping this debug information (don't specify -keepattributes LocalVariableTable).
You can work around it by disabling optimization (add -dontoptimize to your proguard-project.txt).
You can check if the most recent version of ProGuard solves the problem (replace android-sdk/tools/proguard/lib/proguard.jar with the latest version from the ProGuard site).
If updating to the latest version of ProGuard doesn't help, you can report a bug.
I resolved it myself. In onActivityResult ( where this error was getting thrown ) in one place I was not initializing an Integer variable. By initializing it, the issue got resolved. Very weird. If anyone can explain this appropriately, I'll recomend his/her answer.
Before:
int x;
After
int x = 0;
Thats it!
I think eclipse failed to recognized that initialize local variable before using it. So It does not showing warning to user while writing the code. But adt failed to compile file.
According to TanDroiD if you initialize variable your problem will be solved.
I had a similar issue, the solution was to put in a -keep class into the proguard config for the causing class. In my situation it was a class from the Fabric (Crashlytics library)
-keep class io.fabric.sdk.android.services.concurrency.DependencyPriorityBlockingQueue { *; }

Unexpected error when proguard the jsoup in android

My android project have Jsoup(1.6.1) as the external library, but proguard(with the default proguard.cfg generated by ADT) tells there are unexpected errors, such as:
[proguard] Unexpected error while evaluating instruction:
[proguard] Class = [org/jsoup/parser/TreeBuilder]
[proguard] Method = [insertInFosterParent(Lorg/jsoup/nodes/Node;)V]
[proguard] Instruction = [64] aload_2 v2
[proguard] Exception = [java.lang.NullPointerException] (null)
[proguard] Unexpected error while performing partial evaluation:
[proguard] Class = [org/jsoup/parser/TreeBuilder]
[proguard] Method = [insertInFosterParent(Lorg/jsoup/nodes/Node;)V]
[proguard] Exception = [java.lang.NullPointerException] (null)
I have found many posts with the similiar issue for other libraries, and -dontoptimize can remove such errors, but it would degrade the optimization (as the default value in proguard.cfg: -optimizationpasses 5)
Anyone could help me on this? or is it a potential issue of Jsoup?
I had the same issue.
Resolved it by using the latest version of Proguard (4.6) instead of the version bundled with the android sdk (4.4).
This looks like a bug in ProGuard. You should check if it hasn't been fixed in the latest release. Otherwise, you can report the bug on ProGuard's bug tracker at Sourceforge. In this case, the problem may be easy to reproduce. You can probably work around it by reducing the number of optimization passes.

Categories

Resources