setContentView 正在使用非 SDK 接口
setContentView is using non-SDK interface
当我 运行 我的应用程序在模拟器中使用 API 28 时,控制台会给我以下警告:
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)
我一直在调试它,我发现它来自调用:setContentView(R.layout.activity_main)
,所以有没有另一种方法来设置 activity 的布局,或者这个方法是已更新,因此当 运行 在具有 android API 28?.
的设备上时,它不会抛出该警告
只是一个warning
。
你应该阅读 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.
很有可能您传递给 setContentView()
的布局 ID 包含来自使用非 SDK 接口的第 3 方库的一些视图。此警告告诉您正在发生这种情况,但您所能做的就是
- 等待第 3 方修复他们的库
- 从您的布局中删除那些第 3 方视图
目前,这只是一个警告;实际上不会发生什么不好的事情。但在 Android 的 未来 版本中,它可能 成为 一个真正的问题。系统只是给你时间想办法。
问题中的警告,computeFitSystemWindows
和makeOptionalFitsSystemWindows
其实是support库或者androidx库通过反射使用的。您可以通过简单地在 AppCompatDelegateImpl
.
中搜索这两个方法来验证它
希望以后可以解决这个问题。
更新 1
最近我在 Firebase 测试实验室测试应用程序时,这 2 个 API 和其他一些 API 被标记
One possible root cause for this warning is Google-owned library UI Toolkit. No action need be taken at this time.
或
One possible root cause for this warning is Google-owned library Android WebView. No action need be taken at this time.
对于那些在 Android 9 上获得 Accessing hidden method XYZ
的人(饼图,API 28):
一些在 Android 9 中列入灰名单的方法随后在 Android 10 中列入白名单。在寻找灰名单方法的任何替代方法之前,请检查 https://developer.android.com/about/versions/10/non-sdk-q#greylist-now-public
目前这不适用于 OP 问题(computeFitSystemWindows
、makeOptionalFitsSystemWindows
)中的方法,但可能会在未来的 Android 版本中更改。
另请参阅 https://developer.android.com/about/versions/10/non-sdk-q#greylist-now-restricted,其中显示:
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.
例如Android 9 浅灰名单过滤器报告的所有常用方法:
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)
现在在 Android 10 中被列入白名单,因此可以安全地忽略 logcat 警告(至少在 Android 11 之前可能会再次将它们列入灰名单:))。
我遇到了这个问题。我刚刚将 buildToolsVersion
、targetSdkVersion
和 all dependencies
升级到最新版本,现在问题似乎已解决。
您在发布应用时也会在 Google Play 管理中心收到此类警告。它们在发布前报告中显示为 'Stability' 警告。
暂时忽略它们,因为它们超出了您的控制范围。如果在某个时候 Google 更新他们的 SDK 以不使用反射,这些警告将会消失。
当我 运行 我的应用程序在模拟器中使用 API 28 时,控制台会给我以下警告:
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)
我一直在调试它,我发现它来自调用:setContentView(R.layout.activity_main)
,所以有没有另一种方法来设置 activity 的布局,或者这个方法是已更新,因此当 运行 在具有 android API 28?.
只是一个warning
。
你应该阅读 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.
很有可能您传递给 setContentView()
的布局 ID 包含来自使用非 SDK 接口的第 3 方库的一些视图。此警告告诉您正在发生这种情况,但您所能做的就是
- 等待第 3 方修复他们的库
- 从您的布局中删除那些第 3 方视图
目前,这只是一个警告;实际上不会发生什么不好的事情。但在 Android 的 未来 版本中,它可能 成为 一个真正的问题。系统只是给你时间想办法。
问题中的警告,computeFitSystemWindows
和makeOptionalFitsSystemWindows
其实是support库或者androidx库通过反射使用的。您可以通过简单地在 AppCompatDelegateImpl
.
希望以后可以解决这个问题。
更新 1
最近我在 Firebase 测试实验室测试应用程序时,这 2 个 API 和其他一些 API 被标记
One possible root cause for this warning is Google-owned library UI Toolkit. No action need be taken at this time.
或
One possible root cause for this warning is Google-owned library Android WebView. No action need be taken at this time.
对于那些在 Android 9 上获得 Accessing hidden method XYZ
的人(饼图,API 28):
一些在 Android 9 中列入灰名单的方法随后在 Android 10 中列入白名单。在寻找灰名单方法的任何替代方法之前,请检查 https://developer.android.com/about/versions/10/non-sdk-q#greylist-now-public
目前这不适用于 OP 问题(computeFitSystemWindows
、makeOptionalFitsSystemWindows
)中的方法,但可能会在未来的 Android 版本中更改。
另请参阅 https://developer.android.com/about/versions/10/non-sdk-q#greylist-now-restricted,其中显示:
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.
例如Android 9 浅灰名单过滤器报告的所有常用方法:
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)
现在在 Android 10 中被列入白名单,因此可以安全地忽略 logcat 警告(至少在 Android 11 之前可能会再次将它们列入灰名单:))。
我遇到了这个问题。我刚刚将 buildToolsVersion
、targetSdkVersion
和 all dependencies
升级到最新版本,现在问题似乎已解决。
您在发布应用时也会在 Google Play 管理中心收到此类警告。它们在发布前报告中显示为 'Stability' 警告。
暂时忽略它们,因为它们超出了您的控制范围。如果在某个时候 Google 更新他们的 SDK 以不使用反射,这些警告将会消失。