Gson: Android P API Compatibility

Created on 18 Sep 2018  路  5Comments  路  Source: google/gson

I installed my app on Android P, there was a dialog showing "Detected problems with API compatibility (visit g.co/dev/appcompat for more info)" every time i launched my app. I enabled the new StrictMode feature and I got the stack trace:

09-18 14:42:15.389 27929-27929/com.xxx.xxx D/StrictMode: StrictMode policy violation: android.os.strictmode.NonSdkApiUsedViolation: Lsun/misc/Unsafe;->theUnsafe:Lsun/misc/Unsafe;
        at android.os.StrictMode.lambda$static$1(StrictMode.java:428)
        at android.os.-$$Lambda$StrictMode$lu9ekkHJ2HMz0jd3F8K8MnhenxQ.accept(Unknown Source:2)
        at java.lang.Class.getDeclaredField(Native Method)
        at com.google.gson.internal.UnsafeAllocator.create(UnsafeAllocator.java:41)
        at com.google.gson.internal.ConstructorConstructor$14.<init>(ConstructorConstructor.java:221)
        at com.google.gson.internal.ConstructorConstructor.newUnsafeAllocator(ConstructorConstructor.java:220)
        at com.google.gson.internal.ConstructorConstructor.get(ConstructorConstructor.java:96)
        at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory.create(ReflectiveTypeAdapterFactory.java:101)
        at com.google.gson.Gson.getAdapter(Gson.java:457)
        at com.google.gson.internal.bind.CollectionTypeAdapterFactory.create(CollectionTypeAdapterFactory.java:53)
        at com.google.gson.Gson.getAdapter(Gson.java:457)
        at retrofit2.converter.gson.GsonConverterFactory.responseBodyConverter(GsonConverterFactory.java:63)
        at retrofit2.Retrofit.nextResponseBodyConverter(Retrofit.java:330)
        at retrofit2.Retrofit.responseBodyConverter(Retrofit.java:313)
        at retrofit2.ServiceMethod$Builder.createResponseConverter(ServiceMethod.java:739)
        at retrofit2.ServiceMethod$Builder.build(ServiceMethod.java:172)
        at retrofit2.Retrofit.loadServiceMethod(Retrofit.java:170)
        at retrofit2.Retrofit$1.invoke(Retrofit.java:147)
        at java.lang.reflect.Proxy.invoke(Proxy.java:1006)

So there is any solution or workaround not to reflect system non-open api?

Most helpful comment

I can confirm this is in latest version 2.8.5

This warning also appears in Google Play Developer console under compatibility issues.

All 5 comments

I can confirm this is in latest version 2.8.5

This warning also appears in Google Play Developer console under compatibility issues.

This is still in the latest version 2.8.6, and is still appearing as a warning on the Google Play Developer console.

+1

Add androidx multidex in build.gradle it's working for me
implementation 'androidx.multidex:multidex:2.0.1'

Was this page helpful?
0 / 5 - 0 ratings

Related issues

RobMans426 picture RobMans426  路  20Comments

inder123 picture inder123  路  17Comments

GoogleCodeExporter picture GoogleCodeExporter  路  20Comments

GoogleCodeExporter picture GoogleCodeExporter  路  14Comments

GoogleCodeExporter picture GoogleCodeExporter  路  32Comments