Skip to main content
 首页 » 编程设计

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

2024年07月26日20mengfanrong

我在 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

请您参考如下方法:

我遇到了类似的问题,我通过在 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() 
    ); 
} 

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

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

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

Google's documentation on StrictMode还提供了一些额外的指导:

If you find violations that you feel are problematic, there are a variety of tools to help solve them: threads, Handler, AsyncTask, IntentService, etc. But don't feel compelled to fix everything that StrictMode finds. In particular, many cases of disk access are often necessary during the normal activity lifecycle. Use StrictMode to find things you did by accident. Network requests on the UI thread are almost always a problem, though.