Method One:
1. decompile the APK file using the-D option of Apktool
Java-jar Apktool.jar d-d target.apk-o output
2. Add android:debuggable= "True" to the application node of Androidmanifest
3. Add the following code to the OnCreate of the class at the entry point to wait for debugging
invoke-static{}, Landroid/os/debug;->waitfordebugger () V
4. Back to compile apk
Java-jar Apktool.jar b-d Output-o newtarget.apk
5. Sign the APK
Java-jar Signapk.jar Testkey.x509.pem testkey.pk8 newtarget.apk signed.apk
6. Install the signed apk into the phone or simulator
ADB install signed.apk
7. Import the Smali code from 1 into Android studio
File→open→output directory → next Breakpoint
8. Open Monitor to find the appropriate process
Run →monitor or Tools->android->android Device Monitor
9. Configure Remote debugging options
Run→editor Configurations→defaults→remote, click on the + sign add a, host for Localhost,port for 8700
10. Open the APK and click on the green bug to start debugging
Method Two: No need to modify the original apk file
1. decompile the APK file with tools such as Android killer
2. Insert the Smali code into Android studio and install the Smaliidea plugin
File→settings→plugins→install plugin from disk ... →restart
3. Configure remote debugging options to open monitor
4. Use ADB to start the APK in debug mode
ADB shell am start-d-N package/activitiyname
5. Start debugging under Breakpoint, add register in Watch
Two ways to debug Android app