- Apk-tool 1.4.1 and NetBeans 6.8. Use these versions, not the latest ones! Currently, the latest versions of apk-tool and NetBeans do not allow to debug Smali code.
- Java, JDK and other stuff installed in your system to make Apk-tool and NetBeans working
- Decode your .apk file to
out
directory, use-d
option:java -jar apktool.jar d -d my.app.apk out
-
Add
android:debuggable="true"
attribute to<application>
section inout/AndroidManifest.xml
file. -
Build
out
directory to .apk file:java -jar apktool.jar b -d out my.app.to.debug.apk
- Sing and install
my.app.to.debug.apk
to the Android device used for debugging - Delete
out/build
folder - Run NetBeans, click "File" -> "New Project". Choose "Java"->"Java Project with Existing Sources". Click "Next".
- Specify
out
as "Project Folder". Click "Next". - Add
out/smali
folder to the "Source Package Folder" list. Click "Next" and then "Finish". - Start
my.app.to.debug.apk
on the device, run DDMS, find your application on a list and click it. Note port information in last column - it should be something like86xx / 8700
". - In Netbeans, click "Debug" -> "Attach Debugger" -> select "JPDA" and set "Port" to
8700
(or whatever you saw in previous step). Rest of fields should be ok, click "OK". - Debugging session should start: you will see some info in a log and debugging buttons will show up in top panel.
- Set breakpoint. You must select line with some instruction, you can't set breakpoint on lines starting with ".", ":" or "#".
- Trigger some action in application. If you run at breakpoint, then thread should stop and you will be able to debug step by step, watch variables, etc.
Questions are welcome. Have a nice day :)
P.S. If you have problems with breakpoints, this may help.
Thank you so much for this. You saved my life.
ReplyDeleteI'll be indebted to you for this.
I'm glad I could help you :)
Deleteafter step 3 I am get an exception. that the aapt was not found, although I have aapt in the same folder. I tried it from different directories but it gives me the same error. below is the excption details. I am a bit confused
ReplyDeleteI: Checking whether sources has changed...
I: Smaling...
I: Checking whether resources has changed...
I: Building resources...
Exception in thread "main" brut.androlib.AndrolibException: brut.common.BrutException: could not exec command: [aapt, p, -F, /tmp/APKTOOL4160944918573250929.tmp, -I, /root/apktool/framework/1.apk, -S, /home/lab2alex/Documents/out/res, -M, /home/lab2alex/Documents/out/AndroidManifest.xml]
at brut.androlib.res.AndrolibResources.aaptPackage(AndrolibResources.java:193)
at brut.androlib.Androlib.buildResourcesFull(Androlib.java:301)
at brut.androlib.Androlib.buildResources(Androlib.java:248)
at brut.androlib.Androlib.build(Androlib.java:171)
at brut.androlib.Androlib.build(Androlib.java:154)
at brut.apktool.Main.cmdBuild(Main.java:174)
at brut.apktool.Main.main(Main.java:59)
Caused by: brut.common.BrutException: could not exec command: [aapt, p, -F, /tmp/APKTOOL4160944918573250929.tmp, -I, /root/apktool/framework/1.apk, -S, /home/lab2alex/Documents/out/res, -M, /home/lab2alex/Documents/out/AndroidManifest.xml]
at brut.util.OS.exec(OS.java:87)
at brut.androlib.res.AndrolibResources.aaptPackage(AndrolibResources.java:191)
... 6 more
Caused by: java.io.IOException: Cannot run program "aapt": java.io.IOException: error=2, No such file or directory
at java.lang.ProcessBuilder.start(ProcessBuilder.java:488)
at java.lang.Runtime.exec(Runtime.java:610)
at java.lang.Runtime.exec(Runtime.java:483)
at brut.util.OS.exec(OS.java:78)
... 7 more
Caused by: java.io.IOException: java.io.IOException: error=2, No such file or directory
at java.lang.UNIXProcess.(UNIXProcess.java:164)
at java.lang.ProcessImpl.start(ProcessImpl.java:81)
at java.lang.ProcessBuilder.start(ProcessBuilder.java:470)
... 10 more
you are probably on linux, and current directory is not on the path except when explicit called (./blahblah). move aapt to path folder, i.e /usr/local/bin
DeleteLinux:
DeleteDownload apktool-install-linux-* file
Download apktool-* file
Unpack both to /usr/local/bin directory (you must have root permissions)
Is it working with Apktool v2.0.0-Beta4? Apktool 1.4.1 is old and does not work with a lot of apk. The code produces by Apktool v2.0.0-Beta4 doesn't seem the be wrapped in classes for use in IDE
ReplyDeleteIT IS!!!!!!! :D THANKS
Deletecan any one post compiled Apktool v2.0.0-Beta4 .jar file ? i can't rebuild it in windows
DeleteHere is a detailed instruction how to build apktool from sources (for Windows):
Deletehttp://codedigging.com/2014/01/how-to-build-android-apktool-2-00-beta-from-sources/
It's tested and work (at least, for me)
Apktool v2.0.0-a7b06f-SNAPSHOT - a tool for reengineering Android apk files with smali v2.0.3-a7b06f16 and baksmali v2.0.3-a7b06f16
Deletehttp://www73.zippyshare.com/v/13712059/file.html
NetBeans выдает ошибку "в подключении отказано". В чем может быть дело? ddms подключается и выдает порты на приложении 8600/8700. Пробовал и тот и другой.
ReplyDeleteЧерт, я уже и забыл про этот пост, а сюда всё ещё что-то пишут... давайте по почте обсудим?
Deletedm.o.kovalenko@gmail.com
В таких случаях попробуйте поменять свой host на localhost (там обычно показывается имя компьютера). После этого у меня подсоединился он, но ни один breakpoint не удалось установить - писал, что место кода не находится ни в одном классе.
DeleteCan you help me please?
ReplyDeleteis there a debug tutorial for apktool 2
Not yet. As far as I know it, apktool2 is beta at the moment. You should build it from source.
Deletethis tutotial works exactly as it is with apktool 2.0.0b7.
DeleteThis comment has been removed by the author.
DeleteHugo, as far as I know it: yes, it works with apktool 2.0.0b7 as well
DeleteIt wasn't a question ehehe tested here, works as it is!
Deletethanks!
This comment has been removed by the author.
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteThis comment has been removed by the author.
DeleteThanks for sharing such a nice post regards...
ReplyDeletetop android app development companies | professional custom website design company
Good post but I was wondering if you could write a litte more on this subject? I’d be very thankful if you could elaborate a little bit further. Appreciate it! Lucky Patcher APK
ReplyDeleteNice Post. ffsensity
ReplyDelete