41

After searching new Android P features, I came across the non-SDK interfaces restriction. and my question is,

What is a non-SDK interface or an SDK interface? What is the difference between them? specially that makes non-SDK once better. Examples of popular SDK and non-SDK interfaces available for android.

P.S. I came across abstract answers differentiating between SDK and API interfaces but it didn't fulfill my questions :/

aya salama
  • 903
  • 1
  • 10
  • 29
  • 1
    Well, there is an explanations in official docs ... what didn't you understand? – Selvin Apr 30 '18 at 12:15
  • 5
    @Selvin As you can notice from my questions, I have a problem identifying a non-sdk interface, I need the what or the identity of it, not the why which the documentation focuses on – aya salama Apr 30 '18 at 14:22

1 Answers1

43

Quoting the documentation:

Generally speaking, SDK interfaces are those ones found documented in the Android framework Package Index.

Not everything in the framework appears in the documentation. Classes, methods, fields, and such marked with @hide in the source code are available at runtime but are not part of the SDK and do not appear in the documentation. These items can only be accessed by unconventional means, such as reflection.

That is what Android P is starting to ban.

For years, I have been advising developers not to access such things, because they are unreliable. Any Android device may not have the hidden stuff, due to changes based on the Android version or device manufacturer/ROM modder tweaks. Now, Google is going to enforce this advice more firmly, at least in some cases.

specially that makes non-SDK once better

They are not "better". However, they may offer access to certain features that are not available in the SDK, for one reason or another (e.g., API is not settled yet).

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • 10
    Google play reports "Issue: Usage of non-SDK interfaces" in *test results for APK* of my app. However I am not using any hidden API in my own source code. The question is how to identify the troublemaking library? – Alexander Farber Oct 09 '18 at 11:56
  • 4
    @AlexanderFarber: On Android 9.0, you should see some messages in LogCat about the non-SDK interface usage. Also on 9.0, you can set up `penaltyListener()` in `StrictMode` and `detectNonSdkApiUsage()` in the `VmPolicy.Builder` to find out about non-SDK API usage in near-real-time. – CommonsWare Oct 09 '18 at 12:33
  • 12
    @AlexanderFarber if you use androidx support library it uses hidden method `computeFitSystemWindows` for `setContentView()` resulting in this violation report on Android P – materemias Oct 23 '18 at 22:49
  • 1
    @materemias So do we just ignore that violation report? – COYG Jun 08 '19 at 19:18
  • I am using AndroidX on 500k+ devices. Do I just drop it? And if yes, what are the alternatives? – c0dehunter Sep 13 '19 at 20:32
  • @PrimožKralj: Neither this question nor this answer pertain to AndroidX. – CommonsWare Sep 13 '19 at 21:07
  • Hmm, I am getting non-SDK violation reports stemming from AndroidX. But I admit I just started researching the issue.. that, and it's saturday 4am. – c0dehunter Sep 13 '19 at 21:10
  • 4
    @PrimožKralj: If you are on the latest versions of those libraries, hopefully the only reports will be for graylist entries, not blacklist ones. It is up to Google (the AndroidX developers) to talk to Google (the people who create the non-SDK interface lists) to get AndroidX working on newer versions of Android. – CommonsWare Sep 13 '19 at 21:12
  • @CommonsWare **Accessing hidden method Landroid/media/AudioManager;->getOutputLatency(I)I (unsupported, reflection, allowed)** I getting this warning in my logcat so how can I solve this? I'm not using **AudioManager** in my project. – Abhi S Mar 21 '22 at 06:18
  • @AbhiS: Presumably, some library that your project uses (directly or transitively) is using that method. – CommonsWare Mar 21 '22 at 11:46
  • Is there any way to tell if something is a non-sdk interface? Is there a straight-forward way to check code to see all the non-sdk interfaces? – SMBiggs Apr 29 '22 at 18:40
  • 1
    @SMBiggs: "Is there any way to tell if something is a non-sdk interface?" -- if you have to use reflection to access it, odds are that it is a non-SDK interface. – CommonsWare Apr 29 '22 at 18:49