简体   繁体   中英

Unsupported API warnings in Google Play Store

I am getting the following warnings in the pre-launch report from Google Play.

I am at a loss as to how to correct these. Any help or recommendations is appreciated I am having lots of issues here:

 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

I had similar issues I got the NonSdkApiUsedViolation Logs by adding the below code in onCreate() of my MainActivity, it gave me the precise location of the API call causing it.

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()
    );
}

When running your application, should the execution of any code trigger a StrictMode violation, you should see a stack trace in the logging output indicating what triggered it:

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

After manually testing your application, searching your log output for StrictMode should help you find these easily.

Google's documentation on StrictMode also provides some additional guidance:

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.

These warnings refer to the usage of restricted non-SDK interfaces. https://developer.android.com/distribute/best-practices/develop/restrictions-non-sdk-interfaces

These calls may lead to incorrect behavior or app crashes. It is recommended to avoid them. All usages belong to blacklist, greylist, or whitelist. If you can't get rid of these usages, check affiliation to list. Only blacklisted calls lead to crashes. Also, just to remind, Android Q (targetSDK=29) has updated blacklist https://developer.android.com/preview/non-sdk-q

If you are using Xamarin, I believe the equivalent of Kailash's answer is:

#if DEBUG
    StrictMode.SetThreadPolicy(
        new StrictMode.ThreadPolicy.Builder()
            .DetectAll()
            .PenaltyLog()
            .Build());

    StrictMode.SetVmPolicy(
       new StrictMode.VmPolicy.Builder()
            .DetectNonSdkApiUsage()
            .PenaltyLog()
            .Build());
#endif // DEBUG

StrictMode policy violation: android.os.strictmode.NonSdkApiUsedViolation: Landroid/view/ViewGroup;->makeOptionalFitsSystemWindows()V at android.os.StrictMode.lambda$static$1(StrictMode.java:407) at android.os.-$$Lambda$StrictMode$lu9ekkHJ2HMz0jd3F8K8MnhenxQ.accept(Unknown Source:2) at java.lang.Class.getDeclaredMethodInternal(Native Method) at java.lang.Class.getPublicMethodRecursive(Class.java:2079) at java.lang.Class.getMethod(Class.java:2066) at java.lang.Class.getMethod(Class.java:1693) at dkJ(:4) at dku(Unknown Source:0) at dhsetContentView(Unknown Source:7) at com.Needzenterprises.needzz.MainActivity.onCreate(Unknown Source:6) at android.app.Activity.performCreate(Activity.java:7957) at android.app.Activity.performCreate(Activity.java:7946) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1307) at androidx.test.runner.MonitoringInstrumentation.callActivityOnCreate(MonitoringInstrumentation.java:2) at android.app.ActivityThread.performLaunchActivity(Activi tyThread.java:3530) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3707) at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83) at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2220) at android.os.Handler.dispatchMessage(Handler.java:107) at android.os.Looper.loop(Looper.java:237) at android.app.ActivityThread.main(ActivityThread.java:8016) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:496) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1076)

What should I do next.....

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM