Using internal (com.android.internal) and hidden (@hide) APIs [Part 3, custom android platform]
[note: if you don’t have time to follow this post, you can go here and download the final results]
In previous posts I’ve shown how to create custom original-android.jar that contained all classes from internal and hidden APIs.
The next obvious step is to modify already existing Android platform (SDK_DIR/platforms/platform-x/android.jar, where X is API Level of your selection). You can just replace android.jar with original-android.jar that you created in Part 2. But then all your projects will be able to use Internal and Hidden APIs without any limitations. This is not convenient. Because in most projects you don’t want to allow this. Even more, you basically want to forbid usage of these APIs (and this is default behavior of ADT/android.jar). But for a selected few projects you will want to enable usage of Internal and Hidden APIs.
In order to achieve this flexibility you’ll need to create a new customized Android platform. When access to Internal and Hidden APIs is not required, you’ll use original Android platform. But when you need those APIs, you’ll use customized Android platform.
Android SDK directory tree
Let’s look how Android SDK is organized:
We need “platforms” folder. Let’s look inside:
We have a list of supported Android platforms here.
Now let’s see how this is related to Eclipse settings. Select your Android project, right click –> Properties –> Android. You’ll see a list of supported platforms (which echoes …/platforms/ folder). Here is a screenshots:
Creating new platform
In order to create custom platform, we need to copy android-9 folder as android-9-internals. And let’s make some modifications:
- Delete android.jar from android-9-internals folder.
- Copy original-android.jar (created in this post) as android.jar.
- Modify build.propfile:
.... ro.build.version.sdk=9 -> ro.build.version.sdk=-9 ... ro.build.version.release=2.3 -> ro.build.version.release=2.3.extended ....
- Restart eclipse. And verify that you are able to see this new platform. Here is what I have:
Why did I choose API Level -9? That’s because it has to be a number, and it can’t be 9 (or any other existing API Level). Otherwise your custom platform won’t be picked up (it will be visible in list, but it won’t work when selected and compilation will pick original platform with that number).
And here is a screenshot of Libraries view (when custom platform is selected for current project):
In previous post I’ve told you how to create original-android.jar which is uncut version of android.jar that is shipped with SDK. In this post, I’ve shown how to create custom Android platform which uses this original-android.jar. This is enough to use Hidden API. But there is one more step for Internal API. That’s because ADT still won’t allow usage of classes from com.android.internals package (see “forbidden” access rule from screenshot above). Next post will show how to customize ADT in order to allow this.
( Next post )