Google Play 控制台警告应用正在使用不受支持的 API
Posted
技术标签:
【中文标题】Google Play 控制台警告应用正在使用不受支持的 API【英文标题】:Google play console warning app is using unsupported API 【发布时间】:2020-06-29 20:42:57 【问题描述】:我已将我的应用上传到 google play 商店,应用报告 2 个警告
以下 API 已列入灰名单,Google 无法保证它们可以在现有的 android 版本上运行。有些可能已经针对您的目标 SDK 受到限制
API Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V 4 识别的事件。仅显示唯一的堆栈跟踪
堆栈跟踪 1(statck 跟踪中的 APP 类:在 com.elaxer.Registration2.onCreate(Registration2.java:6))
StrictMode policy violation: android.os.strictmode.NonSdkApiUsedViolation: Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V
at android.os.StrictMode.lambda$static$1(StrictMode.java:428)
at android.os.-$$Lambda$StrictMode$lu9ekkHJ2HMz0jd3F8K8MnhenxQ.accept(Unknown Source:2)
at java.lang.Class.getDeclaredMethodInternal(Class.java)
at java.lang.Class.getPublicMethodRecursive(Class.java:2075)
at java.lang.Class.getMethod(Class.java:2063)
at java.lang.Class.getMethod(Class.java:1690)
at androidx.appcompat.widget.TooltipCompatHandler.cancelPendingShow(TooltipCompatHandler.java:19)
at androidx.appcompat.app.AppCompatDelegateImpl.shouldAnimateActionModeView(AppCompatDelegateImpl.java:268)
at androidx.appcompat.app.AppCompatDelegateImpl.calculateNightMode(AppCompatDelegateImpl.java:4)
at androidx.appcompat.app.AppCompatDelegateImpl.getMenuInflater(AppCompatDelegateImpl.java:0)
at androidx.appcompat.app.AppCompatDelegateImpl.initializePanelMenu(AppCompatDelegateImpl.java:0)
at androidx.appcompat.app.AppCompatDelegateImpl.onKeyUp(AppCompatDelegateImpl.java:0)
at androidx.appcompat.app.AppCompatDelegateImpl.onSaveInstanceState(AppCompatDelegateImpl.java:0)
at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:0)
at androidx.appcompat.app.AppCompatDelegateImpl.updateResourcesConfigurationForNightMode(AppCompatDelegateImpl.java:0)
at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:4)
at com.elaxer.Registration2.onCreate(Registration2.java:6)
at android.app.Activity.performCreate(Activity.java:7144)
at android.app.Activity.performCreate(Activity.java:7135)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271)
at androidx.test.runner.MonitoringInstrumentation.callActivityOnCreate(MonitoringInstrumentation.java:184)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2931)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3086)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1816)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6718)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
堆栈跟踪 2(statck 跟踪中的 APP 类:在 com.elaxer.Splash_one.onCreate(Splash_one.java:45))
StrictMode policy violation: android.os.strictmode.NonSdkApiUsedViolation: Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V
at android.os.StrictMode.lambda$static$1(StrictMode.java:428)
at android.os.-$$Lambda$StrictMode$lu9ekkHJ2HMz0jd3F8K8MnhenxQ.accept(Unknown Source:2)
at java.lang.Class.getDeclaredMethodInternal(Class.java)
at java.lang.Class.getPublicMethodRecursive(Class.java:2075)
at java.lang.Class.getMethod(Class.java:2063)
at java.lang.Class.getMethod(Class.java:1690)
at androidx.appcompat.widget.TooltipCompatHandler.cancelPendingShow(TooltipCompatHandler.java:19)
at androidx.appcompat.app.AppCompatDelegateImpl.shouldAnimateActionModeView(AppCompatDelegateImpl.java:268)
at androidx.appcompat.app.AppCompatDelegateImpl.calculateNightMode(AppCompatDelegateImpl.java:4)
at androidx.appcompat.app.AppCompatDelegateImpl.getMenuInflater(AppCompatDelegateImpl.java:0)
at androidx.appcompat.app.AppCompatDelegateImpl.initializePanelMenu(AppCompatDelegateImpl.java:0)
at androidx.appcompat.app.AppCompatDelegateImpl.onKeyUp(AppCompatDelegateImpl.java:0)
at androidx.appcompat.app.AppCompatDelegateImpl.onSaveInstanceState(AppCompatDelegateImpl.java:0)
at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:0)
at androidx.appcompat.app.AppCompatDelegateImpl.updateResourcesConfigurationForNightMode(AppCompatDelegateImpl.java:0)
at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:4)
at com.elaxer.Splash_one.onCreate(Splash_one.java:45)
at android.app.Activity.performCreate(Activity.java:7144)
at android.app.Activity.performCreate(Activity.java:7135)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271)
at androidx.test.runner.MonitoringInstrumentation.callActivityOnCreate(MonitoringInstrumentation.java:184)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2931)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3086)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1816)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6718)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
API Landroid/view/View;->computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z 确定了 2 起事件。仅显示唯一的堆栈跟踪。
堆栈跟踪 1(statck 跟踪中的 APP 类:在 com.elaxer.Splash_one.onCreate(Splash_one.java:45))
StrictMode policy violation: android.os.strictmode.NonSdkApiUsedViolation: Landroid/view/View;->computeFitSystemWindows(Landroid/graphics/Rect;Landroid/graphics/Rect;)Z
at android.os.StrictMode.lambda$static$1(StrictMode.java:428)
at android.os.-$$Lambda$StrictMode$lu9ekkHJ2HMz0jd3F8K8MnhenxQ.accept(Unknown Source:2)
at java.lang.Class.getDeclaredMethodInternal(Class.java)
at java.lang.Class.getMethod(Class.java:2064)
at java.lang.Class.getDeclaredMethod(Class.java:2047)
at androidx.appcompat.widget.TooltipCompatHandler.<clinit>(TooltipCompatHandler.java:23)
at androidx.appcompat.widget.TooltipCompatHandler.cancelPendingShow(TooltipCompatHandler.java:0)
at androidx.appcompat.app.AppCompatDelegateImpl.shouldAnimateActionModeView(AppCompatDelegateImpl.java:268)
at androidx.appcompat.app.AppCompatDelegateImpl.calculateNightMode(AppCompatDelegateImpl.java:4)
at androidx.appcompat.app.AppCompatDelegateImpl.getMenuInflater(AppCompatDelegateImpl.java:0)
at androidx.appcompat.app.AppCompatDelegateImpl.initializePanelMenu(AppCompatDelegateImpl.java:0)
at androidx.appcompat.app.AppCompatDelegateImpl.onKeyUp(AppCompatDelegateImpl.java:0)
at androidx.appcompat.app.AppCompatDelegateImpl.onSaveInstanceState(AppCompatDelegateImpl.java:0)
at androidx.appcompat.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:0)
at androidx.appcompat.app.AppCompatDelegateImpl.updateResourcesConfigurationForNightMode(AppCompatDelegateImpl.java:0)
at androidx.appcompat.app.AppCompatActivity.setContentView(AppCompatActivity.java:4)
at com.elaxer.Splash_one.onCreate(Splash_one.java:45)
at android.app.Activity.performCreate(Activity.java:7144)
at android.app.Activity.performCreate(Activity.java:7135)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271)
at androidx.test.runner.MonitoringInstrumentation.callActivityOnCreate(MonitoringInstrumentation.java:184)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2931)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3086)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1816)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6718)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
我在 gradle 中使用以下库
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.navigation:navigation-fragment:2.1.0'
implementation 'androidx.navigation:navigation-ui:2.1.0'
testImplementation 'junit:junit:4.12'
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation "androidx.viewpager2:viewpager2:1.0.0"
implementation 'com.google.android.material:material:1.0.0'
implementation 'androidx.recyclerview:recyclerview:1.0.0'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'androidx.legacy:legacy-support-v13:1.0.0'
implementation 'androidx.multidex:multidex:2.0.0'
implementation 'androidx.preference:preference:1.1.0'
implementation "androidx.paging:paging-runtime:2.1.1"
implementation 'androidx.lifecycle:lifecycle-extensions:2.1.0'
implementation "androidx.room:room-runtime:2.2.3"
annotationProcessor "androidx.room:room-compiler:2.2.3"
implementation 'com.google.android.exoplayer:exoplayer:2.9.0'
implementation 'androidx.emoji:emoji:1.0.0'
implementation 'com.github.bumptech.glide:glide:4.10.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.10.0'
implementation 'me.relex:circleindicator:1.2.2@aar'
implementation 'de.hdodenhof:circleimageview:2.1.0'
implementation 'com.iceteck.silicompressorr:silicompressor:2.2.2'
implementation 'com.github.hani-momanii:SuperNova-Emoji:1.0'
implementation 'com.pierfrancescosoffritti.androidyoutubeplayer:core:10.0.5'
implementation 'com.google.firebase:firebase-analytics:17.2.1'
implementation 'com.google.firebase:firebase-core:17.2.1'
implementation 'com.facebook.android:facebook-login:[4,5)'
implementation('com.crashlytics.sdk.android:crashlytics:2.6.8@aar')
transitive = true
implementation 'androidx.exifinterface:exifinterface:1.1.0'
我找不到解决此警告的方法。请帮助我消除这些警告。
【问题讨论】:
【参考方案1】:您的应用正在使用makeOptionalFitsSystemWindows 方法(直接或通过嵌入式库),即non-SDK method/hidden method。
有很多方法可以检测 Test your app for non-SDK interfaces 的问题使用。最简单的是veridex tool 或use StrictMode API。
如何使用严格模式:Create strict mode object 并使用detectNonSdkApiUsage
和penaltyListener
。
public void onCreate()
if (DEVELOPER_MODE)
StrictMode.setThreadPolicy(new ThreadPolicy.Builder()
.detectDiskReads()
.detectDiskWrites()
.detectNetwork() // or .detectAll() for all detectable problems
.penaltyLog()
.build());
StrictMode.setVmPolicy(new VmPolicy.Builder()
.detectNonSdkApiUsage()
.penaltyListener( Executors.newSingleThreadExecutor() , new StrictMode.OnVmViolationListener()... )
.detectLeakedSqlLiteObjects()
.detectLeakedClosableObjects()
.penaltyLog()
.penaltyDeath()
.build());
super.onCreate();
注意:确保使用 Android 9(API 级别 28)来测试和验证问题。
从 Android 9(API 级别 28)开始,平台限制了哪些 您的应用可以使用的非 SDK 接口
【讨论】:
以上是关于Google Play 控制台警告应用正在使用不受支持的 API的主要内容,如果未能解决你的问题,请参考以下文章
Google Play 警告我的构建“不允许任何现有用户升级”
当我的应用程序不使用这些权限时,仍然在 Google Play 控制台中收到那些 SMS 和 CALL LOG 警告?
如何解决有关“使用短信或通话记录权限组”的Google Play警告