Use internal (com.android.internal) and hidden (@hide) API [Part 4, Custom ADT]

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


This article is translated from http://devmaze.wordpress.com/2011/01/18/using-com-android-internal-part-4-customizing-adt/

In the previous article, I described how to create a customized original-android.jar and create a customized android platform to use original-android.jar. This only enables the use of hidden APIs, but also leaves a barrier for internal APIs: ADT. ADT defines a rule to prohibit the use of classes from com.android.internal.

image_thumb30_thumb

There are several ways to bypass this restriction rule:

1) The complete ADT source code can be downloaded, you can remove or modify the code, compile and install a new customized version of ADT. The downside is that you have to configure a 64-bit linux system, download the source code, and compile it. This will take some time, and when the new version of ADT comes out, you will need to do it again.

2) Another way is to modify the bytecode of ADT, just replace the string "com/android/inter/**" with other strings, such as "com/android/internax".

The second method can be automated through scripts and does not require access to the source code. It can also work under windows. This is why I explained the second method in this article.

Modify ADT bytecode

Go to the plugins folder of your eclipse and find the file named com.android.ide.eclipse.adt_*.jar. Make a backup (in case you make a mistake), and copy a copy of the modified file to a separate "experimental" folder, where you can modify the bytecode.

Modify *.jar to *.zip, unzip the file to a separate folder, the following is what I got:

image11

Now go to the com/android/ide/eclipse/adt/internal/project subdirectory and find the AndroidClasspathContainerInitializer.class file.

image12

The file contains the string "com/android/internal/**", the next step is to replace the string with other strings, such as "com/android/internax/**". Changing the length of the string may be no problem, but it is best to replace only one letter and keep the length the same.

I used notepad++ to replace, because it supports non-printing characters, and it will not modify non-printing characters when editing the printing characters.

image13

After modification, save the file in a zip compressed folder with the same file name as the original version. Take mine as an example: com.android.ide.eclipse.adt_8.0.1.v201012062107-82219.zip, and then rename it to *.jar.

Note: Please make sure you compress the files correctly. You can compare the internal directory structure of the modified zip and the original zip.

Now delete the original ADT*.jar file in the eclipse plugins folder, copy the modified version, and restart eclipse.

If there is no problem, it will look like the following figure:

image14

Summary of steps:

  1. Stop eclipse
  2. Obtain the jar file of the adt plugin from the plugins folder of eclipse.
  3. Rename .jar to .zip and unzip it to a separate directory.
  4. 找到com/android/ide/eclipse/adt/internal/project/AndroidClasspathContainerInitializer.class
  5. Replace the string "com/android/internal/**" with "com/android/internax/**"
  6. zip all files
  7. Rename .zip to .jar
  8. Replace the original adt jar file in the eclipse plugins folder with the modified version
  9. Start eclipse.

Guess you like

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