Hide and Internal Classes
During android development, you may need to access some method or classes which is not contained in official SDK.
For example, dalvik.system.VMRuntime
, com.android.internal.app.AlertController
, etc.
Although you can done with Java’s reflection, it is not developer friendly.
Here is a more friendly way to do this.
Preparation
(I’m working on a Mac. But I think procedure is similar if working on other OS.)
Android’s official SDK. We use android-17(4.2.2) here.
Android emulator.
Can run ruby.
Steps
Create an emulator for 4.2.2 OS. Name it as “android422”. (by command line or Eclipse)
Pull all framework libraries to working machine, which contains all hide and internal classes.
emulator -avd android422
adb pull /system/framework/* framework
Get decompiling tools for odex. Download smali-2.0.3.jar
and baksmali-2.0.3.jar
. https://code.google.com/p/smali/
Put them in same directory, run ./create_custom_sdk.rb
Then you use choose the created custom sdk from Eclipse.
Source
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# -- create_custom_sdk.rb --
#!/usr/bin/env ruby
# encoding: utf-8
# clear 'out' directory
system ( "rm -rf out" )
system ( "mkdir out" )
Dir . chdir ( "out" )
# core.odex(optimized dex) file -> dex file
system ( "java -jar ../baksmali-2.0.3.jar -a 17 -d ../framework -x ../framework/core.odex -o internal_core_smali" )
system ( "java -jar ../smali-2.0.3.jar -x -o core.dex internal_core_smali" )
# framework.odex(optimized dex) file -> dex file
system ( "java -jar ../baksmali-2.0.3.jar -a 17 -d ../framework -x ../framework/framework.odex -o internal_framework_smali" )
system ( "java -jar ../smali-2.0.3.jar -x -o framework.dex internal_framework_smali" )
# .dex -> .class, which contains all symbols including hide and internal
system ( "dex2jar core.dex" )
system ( "unzip core_dex2jar.jar -d full-symbol-android" )
system ( "dex2jar framework.dex" )
system ( "unzip framework_dex2jar.jar -d full-symbol-android" )
# copy offical sdk here
system ( "cp -r ~/sdk/android-sdk-macosx/platforms/android-17 android422" )
# unzip offical android.jar, merge full-symbol-android into it
system ( "unzip android422/android.jar -d custom-android" )
system ( "cp -r full-symbol-android/* custom-android" )
Dir . chdir ( "custom-android" )
system ( "zip -r9 internal-android.zip *" )
Dir . chdir ( ".." )
system ( "mv custom-android/internal-android.zip android422/android.jar" )
# Fix some properties to enable custom sdk shown in Eclipse
filename = "android422/build.prop"
text = File . read ( filename )
puts = text . gsub ( /ro\.build\.id=.*/ , "ro.build.id=Custom422" )
. gsub ( /ro\.build\.version\.sdk=17/ , "ro.build.version.sdk=422" )
. gsub ( /ro\.build\.version\.release=.*/ , "ro.build.version.release=4.2.2.c" )
File . open ( filename , "w" ) { | file | file << puts }
filename = "android422/source.properties"
text = File . read ( filename )
puts = text . gsub ( /AndroidVersion\.ApiLevel=17/ , "AndroidVersion.ApiLevel=422" )
. gsub ( /Pkg\.Desc=Android SDK Platform 4\.2\.2/ , "Pkg.Desc=Android SDK Platform Custom422" )
File . open ( filename , "w" ) { | file | file << puts }
# Copy custom sdk to offical sdk's directory
system ( "cp -r android422 ~/sdk/android-sdk-macosx/platforms" )
puts "Done"