proguard Error in android app: -keep class com.gravityrd.* { ; }

Hamed mayahian :

I'm using this line of code in proguard.cfg:

-keep class com.gravityrd.* { ; }

related to the gravityapi Document

and additional java-doc

Here is my appguard.cfg config file:

# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
#   http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
#   public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
# Okio & Okhttp
-keepattributes Signature
-keepattributes Annotation
-keep class com.squareup.okhttp.** { *; }
-keep interface com.squareup.okhttp.** { *; }
-dontwarn com.squareup.okhttp.**
-dontwarn okio.**
-keep public class ir.arvankala.util.SICookie2
-keep public class ir.arvankala.util.SiCookieStore2

# Gson
-keepattributes Signature

# For using GSON @Expose annotation
-keepattributes Annotation

# Gson specific classes
-keep class sun.misc.Unsafe { *; }
#-keep class com.google.gson.stream.** { *; }


# Play services
-dontwarn com.google.android.gms.**

# Play services
-dontwarn com.google.android.gms.**


# crashlytics
-keep class com.crashlytics.** { *; }
-keep class com.crashlytics.android.**
-keepattributes SourceFile,LineNumberTable


-keep public class com.adjust.sdk.** { *; }
-keep class com.google.android.gms.common.ConnectionResult {
    int SUCCESS;
}
-keep class com.google.android.gms.ads.identifier.AdvertisingIdClient {
    com.google.android.gms.ads.identifier.AdvertisingIdClient$Info getAdvertisingIdInfo(android.content.Context);
}
-keep class com.google.android.gms.ads.identifier.AdvertisingIdClient$Info {
    java.lang.String getId();
    boolean isLimitAdTrackingEnabled();
}
-keep class dalvik.system.VMRuntime {
    java.lang.String getRuntime();
}
-keep class android.os.Build {
    java.lang.String[] SUPPORTED_ABIS;
    java.lang.String CPU_ABI;
}
-keep class android.content.res.Configuration {
    android.os.LocaledList getLocales();
    java.util.Locale locale;
}
-keep class android.os.LocaledList {
    java.util.Locale get(int);
}

-keep class * implements com.google.gson.TypeAdapterFactory
-keep class * implements com.google.gson.JsonSerializer
-keep class * implements com.google.gson.JsonDeserializer

-ignorewarnings

-keep class android.support.** { *; }
-keep interface android.support.** { *; }
-keep class androidx.** { *; }
-keep interface androidx.** { *; }
-keepattributes SourceFile,LineNumberTable

-keep public class * implements com.bumptech.glide.module.GlideModule
-keep public enum com.bumptech.glide.load.resource.bitmap.ImageHeaderParser$** {
  **[] $VALUES;
  public *;
}
#-keep class com.gravityrd.* { *; }
-keep class com.gravityrd.** { *; }

but can't build app and i get the following error:

java.lang.NoSuchFieldError
        at libcore.reflect.AnnotationAccess.decodeValue(AnnotationAccess.java:688)
        at libcore.reflect.AnnotationAccess.toAnnotationInstance(AnnotationAccess.java:663)
        at libcore.reflect.AnnotationAccess.annotationSetToAnnotations(AnnotationAccess.java:633)
        at libcore.reflect.AnnotationAccess.getDeclaredAnnotations(AnnotationAccess.java:161)
        at java.lang.reflect.Field.getDeclaredAnnotations(Field.java:234)
        at com.c.a.c.f.g.a(AnnotatedFieldCollector.java:79)
        at com.c.a.c.f.g.a(AnnotatedFieldCollector.java:41)
        at com.c.a.c.f.g.a(AnnotatedFieldCollector.java:36)
        at com.c.a.c.f.b.n(AnnotatedClass.java:349)
        at com.c.a.c.f.b.l(AnnotatedClass.java:321)
        at com.c.a.c.f.z.a(POJOPropertiesCollector.java:379)
        at com.c.a.c.f.z.m(POJOPropertiesCollector.java:308)
        at com.c.a.c.f.z.f(POJOPropertiesCollector.java:196)
        at com.c.a.c.f.p.n(BasicBeanDescription.java:251)
        at com.c.a.c.i.b.a(BasicSerializerFactory.java:346)
        at com.c.a.c.i.g.d(BeanSerializerFactory.java:216)
        at com.c.a.c.i.g.a(BeanSerializerFactory.java:165)
        at com.c.a.c.z.c(SerializerProvider.java:1385)
        at com.c.a.c.z.d(SerializerProvider.java:1336)
        at com.c.a.c.z.a(SerializerProvider.java:510)
        at com.c.a.c.z.a(SerializerProvider.java:713)
        at com.c.a.c.i.k.a(DefaultSerializerProvider.java:308)
        at com.c.a.c.s.b(ObjectMapper.java:3893)
        at com.c.a.c.s.a(ObjectMapper.java:3207)
        at com.gravityrd.recengclient.webshop.GravityClient.sendPostRequest(GravityClient.java:187)
        at com.gravityrd.recengclient.webshop.GravityClient.sendRequest(GravityClient.java:130)
        at com.gravityrd.recengclient.webshop.GravityClient.sendRequest(GravityClient.java:105)
        at com.gravityrd.recengclient.webshop.GravityClient.getItemRecommendation(GravityClient.java:415)
        at ir.arvankala.util.j$3.run(RecomUtil.java:125)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
        at java.lang.Thread.run(Thread.java:818)
     Caused by: java.lang.NoSuchFieldException: NON_EMPTY
        at java.lang.Class.getDeclaredField(Class.java:890)
        at libcore.reflect.AnnotationAccess.decodeValue(AnnotationAccess.java:685)
        at libcore.reflect.AnnotationAccess.toAnnotationInstance(AnnotationAccess.java:663) 
        at libcore.reflect.AnnotationAccess.annotationSetToAnnotations(AnnotationAccess.java:633) 
        at libcore.reflect.AnnotationAccess.getDeclaredAnnotations(AnnotationAccess.java:161) 
        at java.lang.reflect.Field.getDeclaredAnnotations(Field.java:234) 
        at com.c.a.c.f.g.a(AnnotatedFieldCollector.java:79) 
        at com.c.a.c.f.g.a(AnnotatedFieldCollector.java:41) 
        at com.c.a.c.f.g.a(AnnotatedFieldCollector.java:36) 
        at com.c.a.c.f.b.n(AnnotatedClass.java:349) 
        at com.c.a.c.f.b.l(AnnotatedClass.java:321) 
        at com.c.a.c.f.z.a(POJOPropertiesCollector.java:379) 
        at com.c.a.c.f.z.m(POJOPropertiesCollector.java:308) 
        at com.c.a.c.f.z.f(POJOPropertiesCollector.java:196) 
        at com.c.a.c.f.p.n(BasicBeanDescription.java:251) 
        at com.c.a.c.i.b.a(BasicSerializerFactory.java:346) 
        at com.c.a.c.i.g.d(BeanSerializerFactory.java:216) 
        at com.c.a.c.i.g.a(BeanSerializerFactory.java:165) 
        at com.c.a.c.z.c(SerializerProvider.java:1385) 
        at com.c.a.c.z.d(SerializerProvider.java:1336) 
        at com.c.a.c.z.a(SerializerProvider.java:510) 
        at com.c.a.c.z.a(SerializerProvider.java:713) 
        at com.c.a.c.i.k.a(DefaultSerializerProvider.java:308) 
        at com.c.a.c.s.b(ObjectMapper.java:3893) 
        at com.c.a.c.s.a(ObjectMapper.java:3207) 
        at com.gravityrd.recengclient.webshop.GravityClient.sendPostRequest(GravityClient.java:187) 
        at com.gravityrd.recengclient.webshop.GravityClient.sendRequest(GravityClient.java:130) 
        at com.gravityrd.recengclient.webshop.GravityClient.sendRequest(GravityClient.java:105) 
        at com.gravityrd.recengclient.webshop.GravityClient.getItemRecommendation(GravityClient.java:415) 
        at ir.arvankala.util.j$3.run(RecomUtil.java:125) 
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112) 
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587) 
        at java.lang.Thread.run(Thread.java:818)

Any help please to solve the problem :)

tynn :

You're configuration regarding the Gravity API is correct:

-keep class com.gravityrd.* { ; }

The NON_EMPTY field is defined in the context of Jackson which is being used as the JSON serializer. As stated in the jackson-docs wiki:

While there are no standardized settings for ProGuard usage, users have contributed sample settings that may be of use.

The most pessimistic suggesting should resolve your issue, but since Jackson isn't a small library, you might want to iterate and improve it.

# Jackson
-keep @com.fasterxml.jackson.annotation.JsonIgnoreProperties class * { *; }
-keep @com.fasterxml.jackson.annotation.JsonCreator class * { *; }
-keep @com.fasterxml.jackson.annotation.JsonValue class * { *; }
-keep class com.fasterxml.** { *; }
-keep class org.codehaus.** { *; }
-keepnames class com.fasterxml.jackson.** { *; }
-keepclassmembers public final enum com.fasterxml.jackson.annotation.JsonAutoDetect$Visibility { 
    public static final com.fasterxml.jackson.annotation.JsonAutoDetect$Visibility *;
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=165596&siteId=1