Google Play 商店中不支持的 API 警告

Muh*_*man 18 android unity-game-engine

我在 Google Play 的发布前报告中收到以下警告。

我不知道如何纠正这些。感谢任何帮助或建议,我在这里遇到很多问题

Android compatibility
 We’ve detected that your app is using unsupported APIs. Tests may not have found all unsupported APIs. Learn more
 
 Unsupported
  12 warnings identified
 The following APIs are greylisted and Google can’t guarantee that they will work on existing versions of Android. Some may be already be restricted for your target SDK
 
 
 API Ljava/lang/invoke/MethodHandles$Lookup;-><init>(Ljava/lang/Class;I)V
 11 occurrences identified. Only unique stack traces are shown.
  
 API Landroid/content/Context;->bindServiceAsUser(Landroid/content/Intent;Landroid/content/ServiceConnection;ILandroid/os/Handler;Landroid/os/UserHandle;)Z
 1 occurrence identified
  
 API Landroid/media/AudioSystem;->getPrimaryOutputFrameCount()I
 1 occurrence identified
  
 API Landroid/media/AudioSystem;->getPrimaryOutputSamplingRate()I
 1 occurrence identified
  
 API Landroid/view/textclassifier/logging/SmartSelectionEventTracker$SelectionEvent;->selectionAction(III)Landroid/view/textclassifier/logging/SmartSelectionEventTracker$SelectionEvent;
 1 occurrence identified
  
 API Landroid/view/textclassifier/logging/SmartSelectionEventTracker$SelectionEvent;->selectionAction(IIILandroid/view/textclassifier/TextClassification;)Landroid/view/textclassifier/logging/SmartSelectionEventTracker$SelectionEvent;
 1 occurrence identified
  
 API Landroid/view/textclassifier/logging/SmartSelectionEventTracker$SelectionEvent;->selectionModified(II)Landroid/view/textclassifier/logging/SmartSelectionEventTracker$SelectionEvent;
 1 occurrence identified
  
 API Landroid/view/textclassifier/logging/SmartSelectionEventTracker$SelectionEvent;->selectionModified(IILandroid/view/textclassifier/TextClassification;)Landroid/view/textclassifier/logging/SmartSelectionEventTracker$SelectionEvent;
 1 occurrence identified
  
 API Landroid/view/textclassifier/logging/SmartSelectionEventTracker$SelectionEvent;->selectionModified(IILandroid/view/textclassifier/TextSelection;)Landroid/view/textclassifier/logging/SmartSelectionEventTracker$SelectionEvent;
 1 occurrence identified
  
 API Landroid/view/textclassifier/logging/SmartSelectionEventTracker$SelectionEvent;->selectionStarted(I)Landroid/view/textclassifier/logging/SmartSelectionEventTracker$SelectionEvent;
 1 occurrence identified
  
 API Landroid/view/textclassifier/logging/SmartSelectionEventTracker;-><init>(Landroid/content/Context;I)V
 1 occurrence identified
  
 API Landroid/view/textclassifier/logging/SmartSelectionEventTracker;->logEvent(Landroid/view/textclassifier/logging/SmartSelectionEventTracker$SelectionEvent;)V
 1 occurrence identified
Run Code Online (Sandbox Code Playgroud)

小智 14

我遇到了类似的问题,我通过在 MainActivity 的 onCreate() 中添加以下代码获得了 NonSdkApiUsedViolation 日志,它为我提供了导致它的 API 调用的精确位置。

if (BuildConfig.BUILD_TYPE.contentEquals("debug")) {
    StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy
        .Builder()
        .detectAll()             // Checks for all violations
        .penaltyLog()            // Output violations via logging
        .build()
    );

    StrictMode.setVmPolicy(new StrictMode.VmPolicy
        .Builder()
        .detectNonSdkApiUsage()  // Detect private API usage
        .penaltyLog()            // Output violations via logging
        .build()
    );
}
Run Code Online (Sandbox Code Playgroud)

在运行您的应用程序时,如果任何代码的执行触发了StrictMode违规,您应该在日志输出中看到一个堆栈跟踪,指示是什么触发了它:

D/StrictMode: StrictMode policy violation; ~duration=28 ms: android.os.strictmode.DiskReadViolation
  at android.os.StrictMode$AndroidBlockGuardPolicy.onReadFromDisk(StrictMode.java:1596)
  ...
Run Code Online (Sandbox Code Playgroud)

在手动测试您的应用程序后,搜索您的日志输出StrictMode应该可以帮助您轻松找到这些。

Google 关于 StrictMode 的文档还提供了一些额外的指导:

如果您发现您认为有问题的违规行为,有多种工具可以帮助解决它们:线程、处理程序、AsyncTask、IntentService 等。但不要被迫修复 StrictMode 发现的所有内容。特别是,在正常的活动生命周期中,经常需要许多磁盘访问情况。使用 StrictMode 查找您不小心做的事情。但是,UI 线程上的网络请求几乎总是一个问题。

  • 请原谅我的天真,但这到底有什么帮助呢?如果我将上述内容添加到我的代码中,是否有我可以检查的日志或者还有其他内容? (2认同)

小智 2

这些警告涉及受限非 SDK 接口的使用。 https://developer.android.com/distribute/best-practices/develop/restrictions-non-sdk-interfaces

这些调用可能会导致不正确的行为或应用程序崩溃。建议避免使用它们。所有用途均属于黑名单、灰名单或白名单。如果您无法摆脱这些用法,请检查从属关系以列出。只有列入黑名单的呼叫才会导致崩溃。另外,提醒一下,Android Q (targetSDK=29) 已更新黑名单 https://developer.android.com/preview/non-sdk-q

  • 我在谷歌开发者页面上找到了这个确切的信息,但它并没有真正帮助OP或我自己以及像我们这样正在努力寻找这些调用在哪里进行的其他人。我们知道不应进行这些调用,但如果我们在代码中找不到这些调用,我们甚至无法开始找出如何纠正它们。 (9认同)
  • 有关信息,我正在使用 Android Studio,在构建或调试期间,我没有通过 Long 收到任何警告。我仅在开发人员控制台预启动报告中看到这些错误。 (3认同)
  • 我的 2 个应用程序中有 23 个此类问题,所有这些问题都源自 google 的 androidx 库,例如 ViewUtils 等。谈谈讽刺 (2认同)