Sandra Arend
Sandra Arend

Reputation: 27

Trying to execute/debug an existing APK file with Eclipse

I have an existing .APK file without any sources. I want to debug it with Eclipse on Bluestacks (or other) emulator. Eventually, I'd like to set a breakpoint, but for now, I just want to get it to run on the emulator. I'm not talking about just using adb to install it on the emulator and then run there. I've been unsuccessful in getting the resulting .apk, built by Eclipse, to run on the emulator.

Here are the steps I've done:

  1. I renamed the .apk to .zip and unzip into a folder.
  2. In Eclipse, I created a new "Android project from existing code". In the next screen, "Import Projects", I browsed to the folder where the apk was unzipped.

But this project has errors in Eclipse! So I tried the next steps:

  1. I executed apktool on the .apk, and it created a folder which I use for the same import mentioned in step 2. Now the project no longer has errors.
  2. In Eclipse, I "run as" or "debug as" this project as an Android application, and it starts on the emulator.

No good! The logcat shows errors such as "dalvikv - thread exiting with uncaught exception". And there are other logcat messages about being unable to instantiate application and java.lang.ClassNotFoundException.

QUESTION 1: Can someone tell me what other steps are necessary to turn this into a "good" project? Is there something obvious that I'm missing about Classes?

Once I can get it to either "run as" or "debug as" successfully, then I will want to debug it by setting a breakpoint. But I can't seem to get the source folder right. I have .smali files as a result of the apktool step mentioned in step 3. Also, I've tried various tools, such as dex2jar and jd-gui, so that I have .java files. But whenever I point tell Eclipse the folder where these sources are (and I have "search subfolders" checked), Eclipse says "Source not found". And "Edit Source Lookup Path". I also tried putting the sources in the /src folder of the workspace.

QUESTION 2: Where can I put the sources so that Eclipse will find them? Can these source files be either .smali or .java?

Upvotes: 1

Views: 4185

Answers (2)

ribbon
ribbon

Reputation: 11

Question 1: You will have many step to get android project from .apk file. This work is named reversing, decoding...

  • You can use apktool to decompile apk to .smali files
  • Then use javaDecompiler for reversing .smali files to .java files
  • Create project and import .java files into it

Question 2: Try question 1 you can do it.

Notice: if developer who coded that apk use proguard, you only see follow of code.

Upvotes: 0

Royston Pinto
Royston Pinto

Reputation: 6721

So basically what you are trying to do is to extract the source out of a packaged APK file. What you have achieved is the max i could do as well. There's no way to get the exact and true source code due to obfuscations whilst packaging an APK file. So what you have reached to is the max you can get to. I used these tools but never could extract a true .java file as the author may have written. It will contain some compiler addtitons and optimizations which are not understood by eclipse.

Upvotes: 4

Related Questions