Xirihanlin 2011.06.03
Original path: http://devmaze.wordpress.com/2011/01/18/using-com-android-internal-part-2-hacking-around/
In the previous article, I explained why it is difficult for us to use internal and hidden APIs without reflection. This is because Android. jar does not contain these APIs, so no one can reference these classes during compilation.
This article describes how to restore the original Android. jar file. This will allow us to use the internal and hidden APIs as we use open APIs.
How to obtain the original Android. Jar?
We need to modify Android. jar so that it can contain all *. class files (including internal and hidden API classes ). There are two methods:
1) Android is an open source project. We can download the source code and build the compiling environment so that it cannot remove the internal and hidden classes. This method is relatively difficult;
2) Every simulator or real machine will have something equivalent to Android. jar at runtime. We can get the JAR file from here, extract the original. Class file, and copy it to Android. jar of Android SDK.
I will adopt solution 2. It is easy to start and does not need to build a Linux environment or a compilation environment.
Obtain framework. jar from the device
You can use the command line (ADB pull) to download files from simulators or devices, or use ddms (using applications in eclipse or SDK ).
Note: The simulator usually contains code in the. Dex file, while the real machine generally contains the code-odex file in the DEX file of the optimized version. It is difficult to operate odex files, which is why I chose a simulator.
The file equivalent to Android. jar in Android SDK is framework. jar. This file is located in the/system/framework. jar file of the device.
ADB pull/system/framework. Jar
After framework.jaris downloaded from the device, it is renamed as framework.zip and decompressed to a separate folder. It looks like this:
Classes. Dex is exactly what we need.
Create framework-classes.zip
First, we need to convert the. Dex file to. Jar format. You can use the general tool dex2jar. You only need to run:
Dev2jar classes. Dex
When the conversion ends, you should get the classes. Dex. dex2jar. jar file. Rename it framework-classes.zip. Use zippers to access framework-classes.zip/COM/Android/Internal /:
Congratulations, you already have all. class files, including internal and hidden APIs (although only part of internal is confirmed ).
Create original-android.jar
Android. jar of Android SDK is located in android_sdk/platforms/Android-x/Android. Jar (X indicates the API level ).
Copy Android. jar to custom-android.jar. Decompress the package to the custom-android folder. Copy all. class files in framework-classes.zip to the custom-android folder (you need to overwrite all existing. class files ).
Then, compress the custom-androidfile into original-android.zip. Rename the original-android.jar.
Summary
1. Select your target platform x
2. Create a simulator for the target platform x
3. Start the simulator and download/system/framework. jar.
4. Rename framework. jar-> framework.zip
5. Extract classes. Dex from framework.zip
6. Use the dex2jar tool to convert it to classes. Jar
7. Rename classes. jar-> framework-classes.zip
8. Copy Android. jar-> custom-android.zip
9. Decompress custom-android.zip to the custom-android folder.
10. Copy all files in framework-classes.zip to the custom-android folder (overwrite existing files)
11. Compress custom-androidfile into original-android.zip
12. Rename original-android.zip->Original-android.jar
After finishing your work.
Summary
We restored Android. jar to include all the. class files of internal and hidden APIs. This is only the first step. The next step is to create a custom Android platform so that it uses the uncut version of Android. jar and add it to the android SDK platforms folder.