google / google/gson

Android P API Compatibility

Open
#1,387 8 comments 30 reactions 0 assignees View on GitHub
needs-info
Dominant language
Java
Stars
24.2k
Forks
4.5k
Avg merge
6d 4h
Merged PRs (30d)
12

Description

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.(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?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.