Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - Phonegap, Extract code from apk

Tags:

cordova

I am new to Phonegap development. I had developed an app and unfortunately i have lost the entire code. But luckily i have the apk file. Can any one pls help me to extract my code from the apk file (PhoneGap - Andriod) Thanks in advance.

-Vinu

like image 833
Vinu123 Avatar asked Jan 23 '13 10:01

Vinu123


People also ask

Is it possible to extract code from APK?

Use apktool to get the resource files out of the apk. Use dex2jar to get a jar file that contains the classes in a format that Eclipse will like. Create an Eclipse project point it at the resource files and the new jar file. Open the jar file with a zip utility and delete the existing resources.

How can I see the source code of an Android app?

You can see android app has . apk extension. You can extract this apk file like zip files but what you get is only compiled class file you can't simply deal with them. So here comes a tool named apktool, which is used to decompile, rebuild and install frameworks.It decompiles nearly to the source code.

How do I read an APK file?

Viewing the contents of an APK file: Since APK files come in compressed ZIP format, any ZIP decompression tool can open it. So, for viewing the contents of an APK file, all you have to do is rename its extension to . zip and open it. Or, you can open it directly through an open dialogue box of a zip application.


2 Answers

Yes, you can. If you copy your .apk file so that is has the .zip extension you should be able to unzip it like any normal zip archive. From that you will be able to retrieve your assest and res folders as well as your AndroidManifest.xml.

If you have written extensive Java code then you will need to decompile the classes.dex file back into Java. Here is a good SO question that covers it:

decompiling DEX into Java sourcecode

like image 87
Simon MacDonald Avatar answered Nov 03 '22 01:11

Simon MacDonald


If you're trying to decompile someone else's apk, that's prohibited.

If not ;) , let's say that you compiled your apk and deleted the project and you need to retrieve it, you can use Apktool to help you with that:

  • Download Apktool (make sure you've got node.js)
  • After installing apktool open node.js
  • Find the directory where your target apk is at (using node.js)
  • After finding it type on node.js: apktool d yourApk.apk
  • To build a project type: apktool b yourProjectFolder

Hope it helped, if you need some help you can leave a comment that I'll be glad to help you!

like image 42
Kyle Avatar answered Nov 03 '22 01:11

Kyle