1.对apk应用apktool反编译出可调试的smali代码到out文件夹,今朝apktool最新的版本是2.0.0b7。
java -jar apktool_2.0.0b7.jar d -d test.apk -o out
这里必须应用-d参数,如许反编译出来的代码后缀均是java,因为只有java文件才干被eclipse/netbeans辨认调试。
2.设置调试标识表记标帜和寻找主类
在输出的out文件夹中,用文本编辑对象打开AndroidManifest.xml,在application节点中设置属性android:debuggable="true"。
持续在AndroidManifest.xml中,搜刮以下关键字
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
找到含有以上信息的activity节点,记录其android:name属性的值,该值则为其应用的主类。如下面的例子,主类为com.acids.helloworld.MainActivity。
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.acids.helloworld">
<application android:debuggable="true" android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme">
<activity android:label="@string/app_name" android:name="com.acids.helloworld.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>
3.在主类的onCreate事务中添加调试守候。
用文本编辑对象打开主类文件,找到onCreate办法,在第一句前插入invoke-static {}, Landroid/os/Debug;->waitForDebugger()V,记得添加a=0;//的前缀对峙高低一致,成果如下:
a=0;// # virtual methods
a=0;// .method protected onCreate(Landroid/os/Bundle;)V
a=0;// invoke-static {}, Landroid/os/Debug;->waitForDebugger()V
a=0;//
a=0;// .locals 1
a=0;// .param p1, "savedInstanceState" # Landroid/os/Bundle;
a=0;//
a=0;// .prologue
a=0;// .line 11
a=0;// invoke-super {p0, p1}, Landroid/app/Activity;->onCreate(Landroid/os/Bundle;)V
4.保存文件,用apktool从头编译打包为debug.apk
java -jar apktool_2.0.0b7.jar b -d out -o debug.apk
5.对debug.apk(须要对象),我把对象放在了signapk文件夹下,生成debug.sign.apk
java -jar .\signapk\signapk.jar .\signapk\testkey.x509.pem .\signapk\testkey.pk8 .\debug.apk .\debug.sign.apk
6.上传debug.sign.apk至或模仿器,然后安装并运行。这时你会看到法度运行后逗留在白屏界面,这时不要动设备和退出法度,因为法度如今是运行到刚才添加的waitForDebugger代码这里,这行代码的意思是一向挂起中,守候调试器。