This article is translated from https://devmaze.wordpress.com/2011/01/18/using-com-android-internal-part-2-hacking-around/
In the previous article, I explained why it is not easy to use the internal API of the com.android.internal package and the hidden API labeled @hide without the reflection mechanism. This is because the Android.jar file does not have classes that contain internal APIs and hidden APIs, so there is no way to reference these classes at compile time.
This article explains how to restore the original Android.jar so that you can use the internal API and the Hide API, just as you would with a public API.
How to get the original (non-cut) Android.jar?
We need to modify the Android.jar so that it contains all the original class files (both internal and hidden APIs). There are two ways of doing this:
1) Android is an open source project. We can download the source code, customize the build system, and not remove the internal and hidden classes from the Android.jar. This method is more difficult.
2) Each simulator or real device has a package that is equivalent to Android.jar for runtime. We can get this jar, solve the original. class file, and copy it to Android.jar.
I prefer the second approach, which is easier, does not require a Linux machine (if you are working under Windows), does not need to compile all the source code, a custom build system, and so on.
Get Framework.jar from your device
You can download files from the device or emulator using the command line (ADB pull) or DDMS (launched separately from Eclipse, or the Android SDK).
(Note: The emulator always contains code in the. dex file, and the real device typically includes the code in the optimized version of the Dex-odex file.) Using Odex files is often difficult, so this article recommends using an emulator)
The runtime and Android.jar equivalent files in the Android SDK are framework.jar. The file is located in/system/framework/framework.jar.
ADB Pull/system/framework/framework.jar
When Framework.jar is downloaded, renamed to Framework.zip, and then unzip to a separate directory, you should be able to get something like the following:
The file Classes.dex is what we want.
Create Framework-classes.zip
First we need to convert the. dex file to the. jar file format. This can be done with a gadget Dex2jar, you only need to run:
Dex2jar Classes.dex
When the conversion is complete, you will get the Classes.dex.dex2jar.jar file and name it framework-class.zip. Using the zip file Viewer, go to framework-class.zip/com/android/internal:
Wow, we got the internal API and the. class file for the hidden API (although only the internal API was confirmed).
Create Original-android.jar
The Android.jar in the Android SDK is located in android_sdk/Platforms/android-x/android.jar (where X stands for API level, such as x==9).
Copy Android.jar to Custom-android.zip. Unzip to the Custom-android folder. Copy all. class files from Framework-class.zip to the Custom-android folder (you need to replace all existing. class files).
Then the Zip folder Custom-android to Original-android.zip and renamed to Original-android.jar.
Summary of steps
- Select Target Platform x (I use the platform of API Leve 9, so x = = 9)
- Creating a simulator for platform X
- Start the emulator and download the/system/framework/framework.jar file from it
- Rename Framework.jar to Framework.zip
- Extract the Classes.dex from the Framework.zip
- Convert Classes.dex to Classes.jar using Dex2jar
- Rename Classes.jar to Framework-classes.zip
- Copy Android.jar from android_sdk/platforms/android-x/, rename to Custom-android.zip
- Unzip Custom-android.zip to custom-android directory
- Copy all files from Framework-classes.zip to custom-android folder (replace existing files)
- Zip compressed Custom-android folder is Original-android.zip
- Rename Original-android.zip to Original-android.jar
Complete.
Conclusion
We restored the original Android.jar, which contains the internal API and the. class file that hides the API. This is only the first step, the next step is to create a custom platform, use the Android.jar version of the release, and then add to the Android SDK platforms directory.
Original: http://mogoweb.net/archives/92