Using internal (com.android.internal) and hidden (@hide) APIs [Part 4, customizing ADT]
In previous posts I described how to create custom original-android.jar and how to create new custom Android platform that uses this original-android.jar. This was just enough to use Hidden API. But one more barrier left for Internal API: ADT for Eclipse. It has a rule that forbids usage of classes from com.android.internal.
There are several ways to overcome this access rule.
1) Full ADT source code is available for download. And its possible to remove/modify correct line of original code, build it and install new custom version of ADT. Bad thing about it is that you need to setup 64-bit Linux machine, download source code, build it. It takes some time. And when new version of ADT arrives, you’ll need to start all over again.
2) The other way is to just modify ADT’s bytecode. Just replace “com/android/internal/**“ string with another string like “com/android/internax”.
Second step may be automated using scripts. And does not require access to source code and works on Windows too. That’s why I’ll describe second approach in this post.
Modifying ADT bytecode
Go to your eclipse folder, plugins folder. Find file with name that looks like com.android.ide.eclipse.adt_*.jar. Make a backup copy of this file (just in case something goes wrong). And make another copy of this file to a separate “experimental” folder , where all bytecode modification is going to be done.
Rename *.jar to *.zip. Unzip file to a separate folder. Here is what I have:
Now go to com/android/ide/eclipse/adt/internal/project subfolder. Find AndroidClasspathContainerInitializer.class file.
This file contains string “com/android/internal/**”. Next step is to replace this string with another string, say “com/android/internax/**”. It’s probably safe to change length of string, but its better to just replace one letter and leave the length the same.
I did this replacements with notepad++, as it does support non-printable characters and does not touch/modify them when editing printable ones.
When this change is done, just save file. And zip the folder so it has exactly the same name as original one. In my case that would be: com.android.ide.eclipse.adt_8.0.1.v201012062107-82219.zip. Rename it to *.jar.
NOTE: Make sure that you have zipped files correctly. Compare internal root folder structure of modified zip and original zip.
Now delete original ADT *.jar file from eclipse’s plugin folder, and copy over modified version. Then start eclipse.
Here is what you should see in Libraries view if everything went fine:
Summary of steps:
- Stop eclipse.
- Get adt plugin’s jar file from eclipse plugin folder
- Rename .jar to .zip, then unzip to separate folder
- Find com/android/ide/eclipse/adt/internal/project/AndroidClasspathContainerInitializer.class
- Replace string “com/android/internal/**” with “com/android/internax/**” in this file.
- Zip all files back (make sure you did this correctly).
- Rename .zip to .jar .
- Replace original adt’s jar file with modified version in eclipse’s plugin folder.
- Start eclipse.
This is the last step that should be taken in order to enable Internal API without using reflection.
( Next step )