Proguard Overflow of unsigned short value - android

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.

Related

Keep logging while obfuscating with Dexguard

I am trying to make Dexguard not stripping out logging functions when it is shrinking and obfuscating my code. I have therefore commented the following instruction in Dexguard configuration file:
-assumenosideeffects class android.util.Log {...}
Once this instruction is commented, build fails with the following error message :
Execution failed for task ':app:dexguardRelease'.
> Instruction has invalid constant index size ([699742] ldc_w #65536)
I have first thought that the problem was related to Android 64K limits but the build successes when dexguard is disabled or when it is enabled and set to strip out the logging functions.
Is it possible that dexguard has troubles obfuscating functions like Log.d() that can contain long strings as input arguments?
Thanks
You probably have lots of debug strings in this class in combination with an -encryptstrings ** directive.
This will lead to a large number of encrypted strings in a single class leading to errors as described in your post.
I would suggest that you revisit your -encryptstrings rules, and only encrypt the ones that are really sensitive.

Dexguard crashing after library added with native code

After adding a library to project that contains native code (embedded as .so), my app build started to crash when running the dexguard<Flavor><BuildType> task.
The error says:
Caused by: java.io.IOException: Can't read [/home/user/project/app/build/intermediates/transforms/mergeJniLibs/flavor/buildType/folders/2000/1f/main(;;;;;;lib/*/*.so,lib/*/gdb*)] (Can't write resource [lib/x86/filecointainedonlibrary.so] (New string section exceeds the length of the original: 243 > 242))
That might happen when DexGuard obfuscates your native methods.
The latest version 7.1.29 should fix this issue, please give it a try.
Edit: The troubleshooting section of the DexGuard manual describes work-arounds when this happens. They basically keep names of native methods.

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.

Is there a way to make DexGuard exit with an error condition if an error occurs?

I'm currently building an android application using ANT on a Jenkins server.
DexGuard is set to run on release in the custom_rules.xml.
Currently there is an issue when DexGuard tries to convert a method:
[dexguard] Unexpected error while converting:
[dexguard] Class = [o/?]
[dexguard] Method = [?(Ljava/lang/String;)Lo/?;]
[dexguard] Exception = [java.lang.IllegalStateException] (Variable v17 too large for instruction [neg-int v17, v17])
[dexguard] java.lang.IllegalStateException: Variable v17 too large for instruction [neg-int v17, v17]
...
Stack trace
...
[dexguard] Not converting this method
My question is, is there a way to get DexGuard to exit with an error status so that either ANT or Jenkins can mark the build as failed?
At the moment it simply prints the stack trace and continues.
I am currently using the Text-finder plugin for Jenkins as a post build step to match a DexGuard exception. If found it downgrades the build to failed.
DexGuard currently ignores methods that it can't convert from Java bytecode to Dalvik bytecode, for any reason -- notably corrupt input code. In this case, it looks more like a bug in DexGuard itself. We'll fix it as soon as possible, and we'll consider adding a flag to stop with an error status.
(I am the lead developer of ProGuard and DexGuard)

Categories

Resources