Home > Android, hacks > Using internal (com.android.internal) and hidden (@hide) APIs [Part 3, custom android platform]

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

(Parts 1, 2, 3, 4, 5)

[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:

image

We need “platforms” folder. Let’s look inside:

image

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:

image

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:

  1. Delete android.jar from android-9-internals folder.
  2. Copy original-android.jar (created in this post) as android.jar.
  3. 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:

image

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):

image

Conclusions

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 )

Categories: Android, hacks
  1. Jorge
    April 18, 2011 at 23:46 | #1

    Everything goes fine until the end. I add the platform and change adt. Eclipse gives me error loading android. Jar. It says it couldn’t put value into styleable. Class in internal folder location. I’m zipping with winrar and usimg notepad . Any help will be grateful.

    • April 18, 2011 at 23:57 | #2

      My guess is that you use ordinary notepad. You should use notepad++.
      Could you please copy-past here the error message that eclipse gives you?

  2. Jorge
    April 19, 2011 at 06:39 | #3

    This is the error I get http://jorge-portfolio.com/error.jpg . I am using notepad++ to edit the file in adt. I’m using the 2.3.3 platform (Gingerbread). Could it be that Google changed something in the Gingerbread SDK?

    • April 19, 2011 at 10:03 | #4

      Nope, I was able to patch 2.3.3 as well without any issues.
      Could you please send me your customized android.jar file. I want to take a look at it.

  3. Yuriy
    May 17, 2011 at 19:48 | #5

    Hi everyone,

    I am receiving the same error as Jorge. What could be a problem? I really need it working =) Original platform is 9, I believe I follow the instructions carefully.

    By the way, there is an easier way (if you build Android) to use internal APIs – just add /out/target/common/obj/JAVA_LIBRARIES/framework_intermediates/classes-full-debug.jar as an external .jar to the project.
    But it doesn’t work for hidden methods and fields, but there must be a way around.

    • May 17, 2011 at 19:53 | #6

      1. You can use that approach, but you need to get android source code for specific API Level, build it and only then use it. The “get specific API Level source code” and “build it” parts are very time consuming (if you do this for the first time) and require to setup 64bit Linux machine.

      Plus adding external jar imports all classes from that jar into your final .apk file. You normally don’t want that.

      2. As for your problem, check that your custom android.jar is zipped correctly (you could’ve included a top folder). Just compare you custom android.jar and original android.jar archives. Let me know if that didn’t help.

      In case you are in hurry, see post #5. It has links to already prepared android.jar for API Level 9.

      • Yuriy
        May 18, 2011 at 12:39 | #7

        Hi inazaruk,

        Thanks for fast response. Unfortunately I cannot use prepared jars, because my jar should include some custom framework classes.

        android.jar is packed what seems to be fine (structure is the same as original). The error looks the same as for Jorge http://jorge-portfolio.com/error.jpg

  4. freiric
    June 12, 2011 at 14:29 | #8

    Thanks! Great time saver! Another time saver for me was to attach the source to the android.jar. With both tricks, I am now able to navigate through the internals api too. You can find zip for the source in the adt-addons eclipse plugins:

    http://code.google.com/p/adt-addons/source/browse/trunk/source/com.android.ide.eclipse.source.update/plugins/com.android.ide.eclipse.source_8.0.1.201012181425.jar

    • June 14, 2011 at 20:53 | #9

      I used to pack the sources from public android repositories myself. But that takes some time and patience. Thanks for plugin suggestion, it definitely makes life easier.

  5. Jason
    January 24, 2012 at 19:03 | #10

    Hi inazaruk,

    Thanks for the great post.

    I did everything as described, zipped with winrar and modified prop with vim. But when I switched to the new platform Eclipse is giving me this error. In addition to this, the IDE can’t resolve any classes.

    I’m using 2.3.3, I set the build.prop to ro.build.version.sdk=-10

    [2012-01-24 12:00:11 - CCS] Unable to resolve target ‘android-7′
    [2012-01-24 12:00:23 - Framework Resource Parser] Collect permissions failed, class android.Manifest$permission not found in C:\Program Files (x86)\Android\android-sdk\platforms\android-10-internals\android.jar
    [2012-01-24 12:00:23 - Android Framework Parser] failed to collect preference classes

    • Jason
      January 24, 2012 at 21:28 | #11

      I figured out what was wrong. When zipping the file back, it appended an additional directory which threw everything off. But now I’m getting another error. It says it can’t find the class below. I noticed that the framework.jar file didn’t include the “org” directory so I’m guessing this is really missing. Any clue in how to resolve this?

      [2012-01-24 14:24:44 - Framework Resource Parser] Collect preferences failed, class org/apache/harmony/dalvik/ddmc/ChunkHandler not found in C:\Program Files (x86)\Android\android-sdk\platforms\android-10-internals\android.jar

      • May 8, 2012 at 18:49 | #12

        Have you solved this problem? I am having the same issue.

      • bharadwaj
        July 1, 2012 at 22:37 | #13

        hi…did u solve this issue? i m stuck at the same stage

  6. wise86andorid
    February 4, 2012 at 18:17 | #14

    Hi,
    for Androdi 3 or 4 the steps are different? i followed the steps but i get always ” Framework Resource Parser] Collect permissions failed, class android.Manifest$permission not found in.. ”

    thaks

  7. sam
    February 16, 2012 at 12:13 | #17

    Hi,
    Thank you for great tutorial, i have implemented it.I have one problem
    In ITelephony.aidl have one method setMute ,I can not execute in 2.2 it show me error NoSuchMethodError , can provide me the hint how to do this please?
    I have configure the eclipse for access rule and also replace the android.jar from yor github source.
    In 2.3 also i can not access other method endCall.

  8. kashifmehmood
    March 21, 2012 at 08:03 | #18

    [2012-03-21 11:00:11 - Android Framework Parser] failed to collect preference classes
    …. i replace my android.jar of android-15 wid urs and also the file build.prop and i am getting this error….any help please….

  9. Chris
    March 28, 2012 at 08:45 | #19

    Hi,

    This is a great tutorial I have managed to accomplish it but using your android.jar file. How can I prepare my own update file while in case of android-15 emulator there is no classes.dex in the framework.jar file. Could you tell me where can I find this missing file?

    • March 28, 2012 at 09:37 | #20

      Latest android emulators have all all .dex files odexed (optimized dex format). This means that you need to look for framework.odex file. Then convert it to framework.dex file and then continue with tutorial. Unfortunately the “deodex” steps are not covered here.

  10. Chris
    March 28, 2012 at 10:10 | #21

    Thank you for the quick response! I will try it.

  11. slash33
    May 3, 2012 at 11:40 | #22

    Encountered the same problem as Jason on 4.0.1 API 14: [Framework Resource Parser] Collect preferences failed, class org/apache/harmony/dalvik/ddmc/ChunkHandler not found in C:\Program Files (x86)\Android\android-sdk\platforms\android-10-internals\android.jar

    I figured many .class files are different when overwriten (diff between files) so maybe the original android.jar and the framework.jar extracted from the device may be different and not compatible.

    • Yuriy Kulikov
      May 11, 2012 at 22:59 | #23

      Many vendors modify Frameworks/base, especially stuff related to telephony and connectivity (API are not changed, of course). To avoid problems use Android.jar from AOSP build.

  12. June 21, 2012 at 16:55 | #24

    Thanks for this post. I’ve used the files from github for api-level 8, but the new platform doesn’t show up in Eclipse (even after a restart of my machine). Oddly though it is showing up in the AVD manager that I start from the android script from the sdk. I’m using linux (Ubuntu 10.04).

  13. norah
    August 1, 2012 at 13:39 | #25

    I have the same problem as Vance Turnewitsch -> did you solve it?

  14. November 16, 2012 at 15:29 | #26

    in case anyone has a problem finding framework.jar, just download a AOSP ROM with the API version you’re targetting and extract from there, waaaaaaaaaaay simpler ;)

  15. angela
    January 18, 2013 at 03:51 | #27

    ro.build.version.release=2.3 -> ro.build.version.release=2.3.extended (build.prop file)
    not work anymore… =(
    I tried this
    Platform.Version=2.3 -> Platform.Version=2.3.extended (source.properties file)
    and then, it changed on the Build Target list.

  16. Paul
    January 23, 2013 at 19:20 | #28

    Target name and Platform should be changed by modifying following lines in file source.properties.
    – Pkg.Desc
    – Platform.Version

    • Deyan
      January 24, 2013 at 11:38 | #29

      Hi! I’ve tried the solutions from “angela” and “Paul” … but still can’t see the custom sdk on the Build Target list. Thanks!

  1. June 15, 2011 at 08:34 | #1

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 34 other followers