Crash in getDeclaredAnnotation when using Proguard - android

I have a android app with 10 library projects and one application project.
2 of the library projects are using jackson library as dependencies. Here is the snipet from build.gradle for both of them
compile 'com.fasterxml.jackson.core:jackson-databind:2.4.4'
compile 'com.fasterxml.jackson.core:jackson-core:2.4.4'
compile 'com.fasterxml.jackson.core:jackson-annotations:2.4.4'
Now my app crashes with the following exception
at java.lang.Class.getDeclaredAnnotations(Native Method) at
com.fasterxml.jackson.databind.introspect.AnnotatedClass.resolveClassAnnotations(AnnotatedClass.java:308)
at
com.fasterxml.jackson.databind.introspect.AnnotatedClass.getAnnotation(AnnotatedClass.java:173)
at
com.fasterxml.jackson.databind.introspect.JacksonAnnotationIntrospector.isIgnorableType(JacksonAnnotationIntrospector.java:97)
at
com.fasterxml.jackson.databind.deser.BeanDeserializerFactory.isIgnorableType(BeanDeserializerFactory.java:870)
at
com.fasterxml.jackson.databind.deser.BeanDeserializerFactory.filterBeanProps(BeanDeserializerFactory.java:635)
at
com.fasterxml.jackson.databind.deser.BeanDeserializerFactory.addBeanProps(BeanDeserializerFactory.java:527)
at
com.fasterxml.jackson.databind.deser.BeanDeserializerFactory.buildBeanDeserializer(BeanDeserializerFactory.java:270)
at
com.fasterxml.jackson.databind.deser.BeanDeserializerFactory.createBeanDeserializer(BeanDeserializerFactory.java:168)
at
com.fasterxml.jackson.databind.deser.DeserializerCache._createDeserializer2(DeserializerCache.java:399)
at
com.fasterxml.jackson.databind.deser.DeserializerCache._createDeserializer(DeserializerCache.java:348)
at
com.fasterxml.jackson.databind.deser.DeserializerCache._createAndCache2(DeserializerCache.java:261)
at
com.fasterxml.jackson.databind.deser.DeserializerCache._createAndCacheValueDeserializer(DeserializerCache.java:241)
at
com.fasterxml.jackson.databind.deser.DeserializerCache.findValueDeserializer(DeserializerCache.java:142)
at
com.fasterxml.jackson.databind.DeserializationContext.findRootValueDeserializer(DeserializationContext.java:394)
at
com.fasterxml.jackson.databind.ObjectMapper._findRootDeserializer(ObjectMapper.java:3169)
at
com.fasterxml.jackson.databind.ObjectMapper._readValue(ObjectMapper.java:3033)
at
com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:1652)
Prior to crash, I could see the following lines in the log
Class resolved by unexpected DEX:
Lcom/vocalocity/Administration/api/support/extensionKit/ExtkitConfig;(0x41ac7088):0x7acd1000
ref [Lcom/fasterxml/jackson/annotation/JsonAutoDetect$Visibility;]
Lcom/fasterxml/jackson/annotation/JsonAutoDetect$Visibility;(0x41ac7088):0x7a356000
(Lcom/vocalocity/Administration/api/support/extensionKit/ExtkitConfig;
had used a different
Lcom/fasterxml/jackson/annotation/JsonAutoDetect$Visibility; during
pre-verification)
Failed processing annotation value
I have tried building the app without proguard using
minifyEnabled = false
Then it works fine. But that is not an option as I need to do obfuscation for my app.
I have tried the following in my proguard file.
-keep class com.fasterxml.jackson.** { *; }
-keepattributes *Annotation*
But it still gives crash.
Could you please tell me how to avoid this crash?

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.

Evernote Android SDK library throws java.lang.VerifyError under R8

Facing notorious java.lang.VerifyError. Initially problem showed up in Fabric. Was able to reproduce (with identical stacktrace) once set minifyEnabled true for debug build.
Caused by java.lang.VerifyError: Verifier rejected class com.evernote.client.conn.mobile.TEvernoteHttpClient: void com.evernote.client.conn.mobile.TEvernoteHttpClient.cancel() failed to verify: void com.evernote.client.conn.mobile.TEvernoteHttpClient.cancel(): [0x6] 'this' argument 'Reference: org.apache.http.client.methods.HttpRequestBase' not instance of 'Reference: org.apache.http.client.methods.AbstractExecutionAwareRequest'
void com.evernote.client.conn.mobile.TEvernoteHttpClient.flush() failed to verify: void com.evernote.client.conn.mobile.TEvernoteHttpClient.flush(): [0x7F] 'this' argument 'Reference: org.apache.http.impl.client.DefaultHttpClient' not instance of 'Reference: org.apache.http.impl.client.CloseableHttpClient' (declaration of 'com.evernote.client.conn.mobile.TEvernoteHttpClient' appears in base.apk)
at com.evernote.client.android.ClientFactory.createNoteStoreClient + 85(ClientFactory.java:85)
I see that typically java.lang.VerifyError issues are recognized as related to difference between code to compile and run against.
This is not the case since code runs just fine when minification is disabled.
The way I see this can be helped is making another rule, but I am failing to understand which classes need to be kept from this error details.
We are already doing
-keep class com.evernote.** { *; }
-keep interface com.evernote.** { *; }
-keep class org.apache.http.** { *; }
-keep interface org.apache.http.** { *; }
... and those classes don't get modified in any way. I've checked it using -printusage ./full-r8-config.txt instruction and checking the output. Classes mentioned in error details do not show up there.
UPDATE 1 day later:
Really strange thing going on here.
So far I have a verified backup plan: switching back to proguard fixes issue.
But in case if I want to stay with R8, here comes:
using -dontshrink, -dontoptimize and -dontobfuscate (all three at once) does no impact;
forcing specific apache.http version dependency does no impact;
I've checked mapping: neither Evernore SDK, nor Apache http classes don't get obfuscated;
issue pertains when app executed on api22 device (emulator, actually);
I was able to debug code once I had -dontobfuscate set. All goes well until Evernote's ClientFactory#createUserStoreClient decides to instantiate TEvernoteHttpClient - the moment program execution touches latter class's constructor - exception thrown.
It looks like it is all good to go, but this verifier fails.
Later update:
Issue filed as a bug for R8: https://issuetracker.google.com/issues/139268389. Please feel free to star it if facing similar situation (all code is in place but VerifyError is thrown)
Try to write below proguard rules.
-dontwarn com.evernote.client.conn.mobile.TAndroidTransport
-dontwarn com.evernote.client.conn.mobile.DiskBackedByteStore
-dontwarn com.evernote.client.conn.mobile.ByteStore
-dontwarn org.apache.commons.codec.binary.Base64

App crash after obfuscation on red5Pro library

Without obfuscation using Proguard, everything is working fine.
When I enable Proguard, app gets crash on this line-
mStream.publish(liveStream.streamName, RECORD_TYPE);
where mStream is the instance of com.red5pro.streaming.R5Stream.
I'm using red5Pro library for broadcasting and not getting any stack trace. I have created an issue on Github also on this repo-
https://github.com/red5pro/streaming-android/issues/119
but didn't get any response yet.
I have tried solutions from other questions but still getting this error.
What should I do in my proguard configuration to resolve this problem?
I have already added following lines in my proguard rules-
-keep class com.red5pro.** { *; }
-dontwarn com.red5pro.**

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

CrashLytics not showing crash reason

I am using crashlytics in my app. It caught a crash in the app, but not telling the line of code where crash occured. It is showing the verify error, but not telling where it is. This link is a screenshot to the report. It is showing ??? about the crash, see this link. How to study this crash now? ._.
Preserve annotations, line numbers, and source file names
-keepattributes *Annotation*,SourceFile,LineNumberTable
If you are using custom exceptions, add this line so that custom exception types are skipped during obfuscation:
-keep public class * extends java.lang.Exception
-printmapping mapping.txt
To skip running ProGuard on Crashlytics, add the following.
This will help speed up builds so that we can ship and test even faster.
-keep class com.crashlytics.** { *; }
-dontwarn com.crashlytics.**
More Info: Follow this link to Configure Crashlytics with Proguard.
https://docs.fabric.io/android/crashlytics/dex-and-proguard.html

Categories

Resources