Use internal (com.android.internal) and hidden (@hide) API [Part 3, custom android platform]

ZT: http://mogoweb.net/archives/104


This article is translated from https://devmaze.wordpress.com/2011/01/18/using-com-android-internal-part-3-custom-android-platform/

In the previous article I showed how to create a customized original-android.jar that contains all the classes in the internal API and hidden API.

The next step is obvious, which is to modify the existing android platform (SDK_DIR/platforms/platform-X/android.jar). You can simply replace android.jar with the original-android.jar created in Part 2, but in this way all your projects can use internal APIs and hidden APIs without restriction. This is not very appropriate, because in most projects, you may not allow it. Moreover, you basically want to prohibit the use of these APIs (this is the default behavior of ADT/android.jar), but internal and hidden APIs are used in a few projects.

In order to achieve this flexibility, a new customized android platform needs to be created. When there is no need to use internal and hidden APIs, you use the original android platform. When you need to access internal and hidden APIs, you use a customized android platform.

Android SDK directory tree

Let's see how the android SDK is organized:

image5

We need the "platforms" directory, go in and see:

image6

Here is a list of supported Android platforms.

Now let's see how this relates to the Eclipse settings. Select an Android project, right click ->Properties -> Android. You can see a list of supported platforms (it reflects the .../platforms/ folder). Below is the screenshot:

image9

Create a new platform

To create a customized platform, you need to copy the android-9 folder, name it android-9-internals, and then make some modifications:

  1. Delete android.jar from the android-9-internals folder.
  2. Copy original-android.jar and rename it to android.jar.
  3. Modify the build.prop file:

    …  

    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, confirm that you can see the new platform, the following is what I see:

image2

Why would I choose API Level -9? That is because it must be a number and cannot be 9 (or other existing API Level), otherwise your customized platform will not be used (it will be displayed in the list, but not Will work, and will take the original platform with the same number when compiling).

The following is a screenshot of the Libraries view (when the custom platform is selected):

image10

to sum up

In the previous article, I explained how to create an uncut version of android.jar, original-android.jar. In this article, I demonstrated how to create a custom android platform that uses the original-android.jar. This is sufficient for using hidden APIs, but it needs to go a step further for using internal APIs. This is because ADT still prohibits the use of classes in the com.android.internals package (please see the screenshot above). In the next article, I will tell you how to customize ADT to allow the use of internal APIs.


Guess you like

Origin blog.csdn.net/lgdlchshg/article/details/23618841