setContentView is using non-SDK interface

22,802

Solution 1

For the warnings in the question, computeFitSystemWindows and makeOptionalFitsSystemWindows are actually used by the support library or androidx library through reflection. You can verify it by simply searching those two methods in the AppCompatDelegateImpl.

Hopefully this can be fixed later.

Update 1

Recently when I test app in Firebase Test Lab, these 2 APIs and some other APIs are marked

One possible root cause for this warning is Google-owned library UI Toolkit. No action need be taken at this time.

Or

One possible root cause for this warning is Google-owned library Android WebView. No action need be taken at this time.

Solution 2

Chances are good that the layout id you’re passing to setContentView() contains some view from a 3rd-party library that uses non-SDK interfaces. This warning is telling you that this is happening, but all you can do is

  • Wait for the 3rd party to fix their library
  • Remove those 3rd-party views from your layout

For now, this is only a warning; nothing bad will actually happen. But in future versions of Android, it might become a real problem. The system is just giving you time to figure it out.

Solution 3

It's just a warning.

You should read the Restrictions on non-SDK interfaces documentation.

Android 9 (API level 28) introduces new restrictions on the use of non-SDK interfaces, whether directly, via reflection, or via JNI. These restrictions are applied whenever an app references a non-SDK interface or attempts to obtain its handle using reflection or JNI. For more information about this decision, see Improving Stability by Reducing Usage of non-SDK Interfaces.

In general, apps should only use the officially documented parts of the classes in the SDK. In particular, this means that you should not plan to access methods or fields that are not listed in the SDK when you interact with a class via semantics such as reflection.

Solution 4

I had this problem. I just upgraded my buildToolsVersion, targetSdkVersion and all dependencies to the last version and the problem seems to be fixed now.

Solution 5

For those getting Accessing hidden method XYZ on Android 9 (Pie, API 28):

Some methods greylisted in Android 9 were then whitelisted in Android 10. Before looking for any alternatives to greylisted methods check https://developer.android.com/about/versions/10/non-sdk-q#greylist-now-public

This does notapply to the methods in OP's question (computeFitSystemWindows, makeOptionalFitsSystemWindows) at the moment but may change in future Android releases.

See also https://developer.android.com/about/versions/10/non-sdk-q#greylist-now-restricted which presents:

non-SDK interfaces from the greylist in Android 9 (API level 28) that are now restricted in Android 10 (API level 29). Wherever possible, alternative APIs are suggested in a comment following the name of the interface.

E.g. all common methods reported by Android 9 light greylist filter:

Accessing hidden method Landroid/graphics/drawable/Drawable;->getOpticalInsets()Landroid/graphics/Insets; (light greylist, linking)
Accessing hidden field Landroid/graphics/Insets;->left:I (light greylist, linking)
Accessing hidden field Landroid/graphics/Insets;->right:I (light greylist, linking)
Accessing hidden field Landroid/graphics/Insets;->top:I (light greylist, linking)
Accessing hidden field Landroid/graphics/Insets;->bottom:I (light greylist, linking)

are now whitelisted in Android 10 so the logcat warn can be safely ignored (at least until Android 11 which may greylist them again :)).

Share:
22,802
Iván Gómez
Author by

Iván Gómez

Updated on May 28, 2021

Comments

  • Iván Gómez
    Iván Gómez almost 3 years

    When I run my application in an emulator with the API 28, the console gives me the following warning:

    W/oaristachimene: Accessing hidden method Landroid/view/View;->computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z (light greylist, reflection) W/oaristachimene: Accessing hidden method Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V (light greylist, reflection)

    I have been debugging it and I found out that it comes from the call: setContentView(R.layout.activity_main), so is there another way to set the layout of an activity or is this method going to be updated so that it doesn't throws that warning when running on a device with android API 28?.