Is there a way to get the source code from an APK file?
Simple way: use online tool https://www.decompiler.com/, upload apk and get source code.
Procedure for decoding .apk files, step-by-step method:
Step 1:
Make a new folder and copy over the .apk file that you want to decode.
Now rename the extension of this .apk file to .zip (e.g. rename from filename.apk to filename.zip) and save it. Now you can access the classes.dex files, etc. At this stage you are able to see drawables but not xml and java files, so continue.
Step 2:
Now extract this .zip file in the same folder (or NEW FOLDER).
Download dex2jar (Don't download the code, click on the releases button that's on the right then download that) and extract it to the same folder (or NEW FOLDER).
Move the classes.dex file into the dex2jar folder.
Now open command prompt and change directory to that folder (or NEW FOLDER). Then write
d2j-dex2jar classes.dex
(for mac terminal or ubuntu write./d2j-dex2jar.sh classes.dex
) and press enter. You now have the classes.dex.dex2jar file in the same folder.Download java decompiler, double click on jd-gui, click on open file, and open classes.dex.dex2jar file from that folder: now you get class files.
Save all of these class files (In jd-gui, click File -> Save All Sources) by src name. At this stage you get the java source but the .xml files are still unreadable, so continue.
Step 3:
Now open another new folder
Put in the .apk file which you want to decode
Download the latest version of apktool AND apktool install window (both can be downloaded from the same link) and place them in the same folder
Open a command window
Now run command like
apktool if framework-res.apk
(if you don't have it get it here)and nextapktool d myApp.apk
(where myApp.apk denotes the filename that you want to decode)
now you get a file folder in that folder and can easily read the apk's xml files.
Step 4:
It's not any step, just copy contents of both folders(in this case, both new folders) to the single one
and enjoy the source code...
How to decompile an APK or DEX file on Android platform?
You need Three Tools to decompile an APK
file.
Dex2jar - Tools to work with android .dex and java .class files
ApkTool - A tool for reverse engineering Android apk files
JD-GUI - Java Decompiler is a tools to decompile and analyze Java 5 “byte code” and the later versions.
for more how-to-use-dextojar. Hope this will help You and all! :)
Is it possible to decompile an Android .apk file?
First, an apk file is just a modified jar file. So the real question is can they decompile the dex files inside. The answer is sort of. There are already disassemblers, such as dedexer and smali. You can expect these to only get better, and theoretically it should eventually be possible to decompile to actual Java source (at least sometimes). See the previous question decompiling DEX into Java sourcecode.
What you should remember is obfuscation never works. Choose a good license and do your best to enforce it through the law. Don't waste time with unreliable technical measures.
Is there a way to decompile multiple android apk at the same time?
This should be fairly easy to do with the standard "find" tool.
cd directory_with_apks
find . -iname "*.apk" -exec apktool d -o {}_out {} \;
Reverse engineering from an APK file to a project
There are two useful tools which will generate Java code (rough but good enough) from an unknown APK file.
Download dex2jar tool from dex2jar.
Use the tool to convert the APK file to JAR:
Windows:$ d2j-dex2jar.bat demo.apk
dex2jar demo.apk -> ./demo-dex2jar.jarMacOS / Linux:
$ d2j-dex2jar.sh -f demo.apk -o demo.jar
Once the JAR file is generated, use JD-GUI to open the JAR file. You will see the Java files.
The output will be similar to:
Then you can use other tools to retrieve the AndroidManifest.xml and resource files (like images, translations, etc...) from the APK file.
Apktool
$ java -jar apktool.jar -q decode -f demo.apk -o outputDir
AXMLParser
$ apkinfo demo.apk
NinjaDroid
$ ninjadroid demo.apk --all --extract
Android - How to decode and decompile any APK file?
To decompile APK Use APKTool.
You can learn how APKTool works on http://www.decompileandroid.com/ or by reading the documentation.
How to correctly re-compile an apk file?
The following is for your reference
Compile, decompile and sign APK using apktool utility.
Download latest apktool version.
Download the batch file and aapt.exe.
Create a folder anywhere in the PC and put all the apktool.jar, aapt.exe and the batch script in that folder.
Open command prompt.
Navigate to the folder where you placed apktool.jar, batch script and the aapt.exe.
Now, you need to install the file using the " IF " command.
Type the following command.
apktool if name-of-the-app.apk
For decompiling use the command "d". The "d" stands for decompile.
apktool d name-of-the-app.apk
After the app is correctly decompiled, a new folder will be created in the same folder where you placed your app. This contains all the xml's and smali files which can be edited for different mode's.
To recompile the app use the following command " B ". The "b" simply means recompile.
apktool b name-of-the-app-folder
The final modded app will be in the "dist" folder located inside the original app folder created by apktool.
Signing the apk
open a new command prompt and change into the sign-apk directory using cmd
move the modified-unsigned apk into this folder
then type the following command -
java -jar signapk.jar certificate.pem key.pk8 path-of-the-folder-contaning-the-apk.apk path-of-the-new-signed-apk.apk
Once compiled, the signed apk will be found in the same folder.
How to Decompiling Apk files that Generated By Android Studio
To decompile the XML files you can use the following tools:
JadX
- https://github.com/skylot/jadxApktool
- https://github.com/iBotPeaches/Apktool
Remember the apktool
which you are using is probably a very old version. Download the latest version of apktool.jar
from https://github.com/iBotPeaches/Apktool/releases/download/2.1.1/apktool_2.1.1.jar
Below are the two process through which you can get the xml files.
Apktool
Method:
- Download the latest apktool jar from https://github.com/iBotPeaches/Apktool/releases/download/2.1.1/apktool_2.1.1.jar
- Run it using
java -jar apktool.jar d <apkfile.apk>
without the angular brackets and substitutingapkfile.apk
with the actual path to the apk file
Jadx
method:
- Download the latest release of jadx from https://github.com/skylot/jadx/releases
- Unzip the file and then goto
bin/
folder - Windows user can double click the
jadx-gui.bat
file - Linux/Mac users can run the shell script
./jadx-gui
- This will open jadx gui through which you can open the apk file.
Reference: Jadx
open dialogue
Related Topics
No Resource Found - Theme.Appcompat.Light.Darkactionbar
Meaning of Top, Ascent, Baseline, Descent, Bottom, and Leading in Android's Fontmetrics
Firebase Fcm Notifications Click_Action Payload
How to Enable/Disable Bluetooth Programmatically in Android
Data Sharing Between Two Applications
Android Customized Button; Changing Text Color
Onactivityresult() Called Prematurely
Is There Any Way in Android to Get the Height of Virtual Keyboard of Device
Android. Fragment Getactivity() Sometimes Returns Null
Deleting Row in SQLite in Android
Android: How to Check If Activity Is Running
Android - Storing/Retrieving Strings with Shared Preferences
How to Disable Scrolling on a Viewpager
Notificationcompat.Builder Deprecated in Android O
Dynamically Add and Remove View to Viewpager
How to Get the First Name and Last Name from Android Contacts
Android Textview with Clickable Links: How to Capture Clicks