Home » Android » java.lang.NoSuchFieldError: PUBLIC_ONLY while using Box api in android in signed build

java.lang.NoSuchFieldError: PUBLIC_ONLY while using Box api in android in signed build

Posted by: admin June 15, 2020 Leave a comment

Questions:

I have developed android application which contains Dropbox,Google drive and Box cloud service. I tested it and everything was working. After that I signed it and I realized that debug apk size was 8.5MB whereas signed apk size was 7MB.Still I tested complete application in which everything was working except Box cloud functionality.I got below exception

        11-28 12:51:14.129: E/AndroidRuntime(2702): FATAL EXCEPTION: main
    11-28 12:51:14.129: E/AndroidRuntime(2702): Process: com.idealtech.mycoud, PID: 2702
    11-28 12:51:14.129: E/AndroidRuntime(2702): java.lang.NoSuchFieldError: PUBLIC_ONLY
    11-28 12:51:14.129: E/AndroidRuntime(2702):     at java.lang.Class.getDeclaredAnnotation(Native Method)
    11-28 12:51:14.129: E/AndroidRuntime(2702):     at java.lang.Class.getAnnotation(Class.java:290)
    11-28 12:51:14.129: E/AndroidRuntime(2702):     at com.b.a.c.f.ae.<clinit>(Unknown Source)
    11-28 12:51:14.129: E/AndroidRuntime(2702):     at com.b.a.c.z.<clinit>(Unknown Source)
    11-28 12:51:14.129: E/AndroidRuntime(2702):     at com.box.boxjavalibv2.jsonparsing.BoxJSONParser.<init>(Unknown Source)
    11-28 12:51:14.129: E/AndroidRuntime(2702):     at com.box.boxjavalibv2.BoxClient.a(Unknown Source)
    11-28 12:51:14.129: E/AndroidRuntime(2702):     at com.box.boxjavalibv2.BoxClient.<init>(Unknown Source)
    11-28 12:51:14.129: E/AndroidRuntime(2702):     at com.box.boxjavalibv2.BoxClient.<init>(Unknown Source)
    11-28 12:51:14.129: E/AndroidRuntime(2702):     at com.box.boxandroidlibv2.BoxAndroidClient.<init>(Unknown Source)
    11-28 12:51:14.129: E/AndroidRuntime(2702):     at com.box.boxandroidlibv2.activities.OAuthActivity.a(Unknown Source)
    11-28 12:51:14.129: E/AndroidRuntime(2702):     at com.box.boxandroidlibv2.activities.OAuthActivity.a(Unknown Source)
    11-28 12:51:14.129: E/AndroidRuntime(2702):     at com.box.boxandroidlibv2.activities.OAuthActivity.onCreate(Unknown Source)
    11-28 12:51:14.129: E/AndroidRuntime(2702):     at android.app.Activity.performCreate(Activity.java:5248)
    11-28 12:51:14.129: E/AndroidRuntime(2702):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1110)
    11-28 12:51:14.129: E/AndroidRuntime(2702):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2162)
    11-28 12:51:14.129: E/AndroidRuntime(2702):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2257)
    11-28 12:51:14.129: E/AndroidRuntime(2702):     at android.app.ActivityThread.access$800(ActivityThread.java:139)
    11-28 12:51:14.129: E/AndroidRuntime(2702):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1210)
    11-28 12:51:14.129: E/AndroidRuntime(2702):     at android.os.Handler.dispatchMessage(Handler.java:102)
    11-28 12:51:14.129: E/AndroidRuntime(2702):     at android.os.Looper.loop(Looper.java:136)
    11-28 12:51:14.129: E/AndroidRuntime(2702):     at android.app.ActivityThread.main(ActivityThread.java:5086)
    11-28 12:51:14.129: E/AndroidRuntime(2702):     at java.lang.reflect.Method.invokeNative(Native Method)
    11-28 12:51:14.129: E/AndroidRuntime(2702):     at java.lang.reflect.Method.invoke(Method.java:515)
    11-28 12:51:14.129: E/AndroidRuntime(2702):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
    11-28 12:51:14.129: E/AndroidRuntime(2702):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
    11-28 12:51:14.129: E/AndroidRuntime(2702):     at dalvik.system.NativeStart.main(Native Method)

Its not getting library which it finds in debug.What do I do to fix this issue?
Please help me. I couldnot release my application because of this issue.
Thanks in advance.

How to&Answers:

I got this issue because of jackson library while compiling it with proguard, I fixed it by adding following lines in proguard file.

-keepnames class com.fasterxml.jackson.** { 
*; 
}
-keepnames interface com.fasterxml.jackson.** { 
    *; 
}