We’d gotten wind of this change a few weeks ago, but now it’s official: Google will be restricting access to non-public APIs in the next version of Android. This means that in Android P and going forward, APIs that are unofficially supported in Android’s SDK will (generally) not be available to developers to use in their apps.
Using unofficial APIs in an app is risky, as it can sometimes cause unexpected issues and lead to bugs and errors when a new release unintentionally changes how the API works. That’s why Google generally recommends sticking to official APIs in the Android SDK, as they’re unlikely to break without warning with the release of a new Android version.
Of course, it’s not like developers want to use undocumented APIs for no reason: sometimes it’s easier to do things using a non-SDK API than through the SDK, and in some cases there’s simply no SDK alternative. That’s why Google wants to make this transition slowly and cautiously. At first, only those non-SDK APIs with low to no usage will be blocked, so as to minimize the impact on developers. In most cases, when a developer attempts to access one of these APIs, they’ll simply see an error such as NoSuchFieldException or NoSuchMethodException.
For situations in which using SDK APIs is possible but likely to be technically challenging, using undocumented APIs will still be allowed until an app is updated to target the latest API level. Eventually, Google plans to broaden these restrictions in future platform versions, but slowly enough to give developers ample time to migrate to official APIs.
But what about those cases where there just isn’t any suitable alternative to a non-SDK API? Thankfully, Google’s thought ahead and has set up a way for developers to request new APIs through a bug tracker when they feel that the current public APIs aren’t enough. If all goes well, this change could potentially help make apps more reliable and stable in the long run.
Image Credit: Michael Stern