D.F.P Delphi Android Native Components classes.dex file merging - android

I have Delphi XE5 without updates.
I might have missunderstood the way I should use the BAT file.
In the build.bat template plus the install.txt, my understanding leads me to think than I should use test_classes.dex to be merged with the original classes.dex that embarcadero provides, in order to run the demos correctly.
However, I am not intereseted in testing the demos. I would like just to use the components inside my own project.
Which files should I merge?
Thanks in advance for your guidance and help.

I found the solution here http://blog.blong.com/2013/11/delphi-and-android-services-part-2.html.
It says:
1) Review the build.bat file and ensure the environment variables are set
correctly:
2) ANDROID needs to point to your Android SDK base directory, e.g.
C:\Users\Public\Documents\RAD Studio\12.0
\PlatformSDKs\adt-bundle-windows-x86-20130522\sdk or
C:\Android\android-sdk-windows
3) ANDROID_PLATFORM needs to point at an installed SDK platform
installation, e.g. %ANDROID%\platforms\android-15 or %
ANDROID%\platforms\android-17. Check for one that is installed.
4) DX_LIB needs to point to the lib subdirectory under the Android SDK
build-tools directory, e.g. %ANDROID%\build- tools\18.0.1\lib or
%ANDROID%\build-tools\android-4.2.2\lib
5) EMBO_DEX needs to point to the Delphi-supplied Android classes.dex
file, wrapped in quotes to take care of any spaces in the path, e.g.
"C:\Program Files (x86)\Embarcadero\RAD
Studio\12.0\lib\android\debug\classes.dex"
6) Run build.bat
7) You should now have a new file in the project directory tree called
java\output\dex\classes.dex
This file replaces the supplied classes.dex and has the Java service
and broadcast receiver compiled classes included in it.
8) Set the new classes.dex for deployment

Related

How to set the local cpp source path in Android studio for prebuild library

I created an App which includes our source code as a native lib (so-file). I'm able to step into it and everything works fine so far with this code.
This native lib links against another native lib which was pre-build on a different machine and which I copied into the jni-abi-folder. I have checked out the svn-repository of this so-file in a different folder parallel to my project and need to be able to debug also into it.
When I now do a break, I can see the method names in the callstack so I assume that the symbols can be loaded, but Android Studio doesn't know where to find the source files.
Under Visual Studio, when I did a break, I could specify the symbols in the symbol path and then an error was displaced that I should navigate to the corresponding source file. Then I only needed to navigate to the folder and it was working.
How can this be done with Android Studio - I have the newest version 3.2.1 installed.
I finally found the solution.
I got a stripped version from my colleague, he basically gave me the version inside his apk which is stripped. Now he gave me directly the build version (I think it is located somewhere in the intermediate directory or so, just search for the name of the lib).
Under Run\Edit Configurations\Debugger\LLDB startup commands the original source directory can be mapped to the source directory on my computer which is different. To achieve this, enter "settings set target.source-map or-dir cur-dir"
There should be a way to find out the original source directory from the so file, but I don't know it right now.
I hope this can help somebody else

How can I extract full android project from apk file? [duplicate]

The hard drive on my laptop just crashed and I lost all the source code for an app that I have been working on for the past two months.
All I have is the APK file that is stored in my email from when I sent it to a friend.
Is there any way to extract my source code from this APK file?
Simplest way: use the online tool Decompiler, upload the apk and get the 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 (rename from filename.apk to filename.zip) and save it. Now you can access the classes.dex files. At this stage, you are able to see drawables, but not the .xml and .java files.
Step 2:
Now extract this .zip file in the same folder or a new folder.
Download dex2jar (Don't download the code, click on the releases button that's on the right, then download the file named dex2jar-X.X.zip) and extract it to the same folder or a new folder.
Move the classes.dex file into the dex2jar folder.
Now open Command Prompt and change the directory to that folder. Then write d2j-dex2jar classes.dex (for Mac 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, Right click on jd-gui, click on Open File, and open classes.dex.dex2jar file from that folder: Now you get the 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 code but the .xml files are still unreadable.
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 the Command Prompt
Now run command apktool if framework-res.apk (if you don't have it get it here)and next
apktool d myApp.apk (myApp.apk denotes the filename that you want to decode)
Now you get a file folder in that folder and can easily read the .xml files.
Step 4:
It's not any step, just copy the contents of both folders (both new folders) to the single one
AND ENJOY THE SOURCE CODE!
This is an alternative description - just in case someone got stuck with the description above. Follow the steps:
download apktool.bat (or apktool for Linux) and apktool_<version>.jar from http://ibotpeaches.github.io/Apktool/install/
rename the jar file from above to apktool.jar and put both files in the same folder
open a dos box (cmd.exe) and change into that folder; verify that a Java Environment is installed (for Linux check the notes regarding required libraries as well)
Start: apktool decode [apk file]
Intermediate result: resource files, AndroidManifest.xml
unzip APK file with an unpacker of your choice
Intermediate result: classes.dex
download and extract dex2jar-0.0.9.15.zip from http://code.google.com/p/dex2jar/downloads/detail?name=dex2jar-0.0.9.15.zip&can=2&q=
drag and drop classes.dex onto dex2jar.bat (or enter <path_to>\dex2jar.bat classes.dex in a DOS box; for Linux use dex2jar.sh)
Intermediate result: classes_dex2jar.jar
unpack classes_dex2jar.jar (might be optional depending on used decompiler)
decompile your class files (e.g. with JD-GUI or DJ Decompiler)
Result: source code
Note: it is not allowed to decompile third party packages; this guide is intended to recover personal source code from an APK file only; finally, the resulting code will most likely be obfuscated
While you may be able to decompile your APK file, you will likely hit one big issue:
it's not going to return the code you wrote. It is instead going to return whatever the compiler inlined, with variables given random names, as well as functions given random names. It could take significantly more time to try to decompile and restore it into the code you had, than it will be to start over.
Sadly, things like this have killed many projects.
For the future, I highly recommend learning a Version Control System, like CVS, SVN and git etc.
and how to back it up.
There is also a new application on the Play Store with which it is possible to decompile an apk (system applications too) and view the source code right on your smartphone. It saves the files to your SD card so you can view it on your computer too. It does not require root or something else.
Just install and have fun. I think this is the easiest way to decompile an app.
apktool is the best thing you can try. I have saved some xml with it, but honestly I don't know how it will work with the .java code.
I would recommend you to have a code repository even if your are the only coder. I've been using Project Locker for my own projects. It gives you free svn and git repos.
These two articles describe how to combine the use of apktool and dex2jar to take an APK file and create an Eclipse project that can build and run it.
http://blog.inyourbits.com/2012/11/extending-existing-android-applications.html
http://blog.inyourbits.com/2012/12/extending-existing-android-applications.html
Basically you:
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
Open the jar file with JDGui to view the source code
Take whatever source code you need from JDGui, stick it in a class inside Eclipse and modify it
Delete that class from the jar file (so you don't have the same class defined multiple times)
Run it.
apktool will work. You don't even need to know the keystore to extract the source code (which is a bit scary). The main downside is that the source is presented in Smali format instead of Java. Other files such as the icon and main.xml come through perfectly fine though and it may be worth your time to at least recover those. Ultimately, you will most likely need to re-write your Java code from scratch.
You can find apktool here. Simply just download apktool and the appropriate helper (for Windows, Linux, or Mac OS). I recommend using a tool such as 7-zip to unpack them.
There are a few ways to do this:
Use the "Profile or Debug APK" feature in Android Studio 3.0.
It allows you to open and explore APKs in Android Studio. Classes are decompiled into smali. Resources are not extracted and things like "Go to Definition", "Find All References" and debugging don't work without the source code (android studio 3.0 canary 9). Some additional smali features might work with smalidea.
Use jadx.
Jadx decompiles the code in a given APK to java source files.
Use apktool.
Apktool is a command line tool which extracts resources and decompiles code into smali for a given apk. You can recompile using apktool also. Here's an example of it in action:
$ apktool d test.apk
I: Using Apktool 2.2.4 on test.apk
I: Loading resource table...
I: Decoding AndroidManifest.xml with resources...
I: Loading resource table from file: 1.apk
I: Regular manifest package...
I: Decoding file-resources...
I: Decoding values */* XMLs...
I: Baksmaling classes.dex...
I: Copying assets and libs...
I: Copying unknown files...
I: Copying original files...
$ apktool b test
I: Using Apktool 2.2.4 on test
I: Checking whether sources has changed...
I: Smaling smali folder into classes.dex...
I: Checking whether resources has changed...
I: Building resources...
I: Building apk file...
I: Copying unknown files/dir...
May be the easy one to see the source:
In Android studio 2.3, Build -> Analyze APK -> Select the apk that you want to decompile.
You will see it's source code.
Link for reference:
https://medium.com/google-developers/making-the-most-of-the-apk-analyzer-c066cb871ea2
This site https://www.apkdecompilers.com/ did it automatically.
I tried the site mentioned in the accepted answer first but that didn't work for me.
I personally recommend Show Java Android App to get the source code. You can download it from play store or from here
based on your condition, if your android apk:
Condition1: NOT harden (by Tencent Legu/Qihoo 360/...)
Choice1: using online service
such as:
using www.javadecompilers.com
goto:
http://www.javadecompilers.com/apk
Note: internally using Jadx
to auto decode from apk to java sourcecode
steps:
upload apk file + click Run + wait some time + click Download to get zip + unzip ->
sources/com/{yourCompanyName}/{yourProjectName}
is your expected java source code
Choice2: decompile/crack by yourself
use related tool to decompile/crack by yourself:
use jadx/jadx-gui convert apk to java sourcecode
download jadx-0.9.0.zip then unzip to got bin/jadx, then:
command line mode:
in terminal run: jadx-0.9.0/bin/jadx -o output_folder /path_to_your_apk/your_apk_file.apk
output_folder will show decoded sources and resources
sources/com/{yourCompanyName}/{yourProjectName} is your expected java sourcecode
GUI mode
double click to run jadx-0.9.0/bin/jadx-gui (Linux's jadx-gui.sh / Windows's jadx-gui.bat)
open apk file
it will auto decoding -> see your expected java sourcecode
save all or save as Gradle project
eg:
Condition2: harden (by Tencent Legu/Qihoo 360/...)
the main method of 3 steps:
apk/app to dex
dex to jar
jar to java src
detailed explanation:
Step1: apk/app to dex
use tool (FDex2/DumpDex) dump/hook out (one or multiple) dex file from running app
steps:
prepare environment
a rooted android
real phone
or emulator
here using Chinese Nox App Player夜神安卓模拟器
install your android apk
to the phone or emulator
installed Xposed Installer
install FDex2/DumpDex into XPosed and enable it
Note: need restart Xposed to make FDex2 work
FDex2 download address, Chinese:
脱壳工具 FDex2-CSDN下载
链接: https://pan.baidu.com/s/1lTF8CN96bxWpFwv7J174lg 提取码: 3e3t
install your android apk to phone/emulator
dump out dex from running app
run FDex2 then click your apk name to enable later to capture/hook out dex
(in phone/emulator) run your app
find and copy out the dump out whole apk resources in /data/data/com/yourCompanyName/yourProjectName
in its root folder normally will find several dex file
Step2: dex to jar
use tool (dex2jar) convert (the specific, containing app logic) dex file to jar file
download dex2jar got dex-tools-2.1-SNAPSHOT.zip, unzip got dex-tools-2.1-SNAPSHOT/d2j-dex2jar.sh, then
sh dex-tools-2.1-SNAPSHOT/d2j-dex2jar.sh -f your_dex_name.dex
eg:
dex-tools-2.1-SNAPSHOT/d2j-dex2jar.sh -f com.xxx.yyy8825612.dex
dex2jar com.xxx.yyy8825612.dex -> ./com.xxx.yyy8825612-dex2jar.jar
Step3: jar to java src
use one of tools:
Jadx
Procyon
GUI tool based on procyon:
Luyten
Bytecode Viewer
CRF
JD-GUI
some others:
Krakatau
Fernflower
Cavaj
convert jar to java src
for from jar to java src converting effect:
Jadx > Procyon > CRF >> JD-GUI
so recommend use: Jadx/jadx-gui
steps:
double click to run jadx-gui
open dex file
File -> save all
eg:
exported java src:
More detailed explanation can see my online ebook Chinese tutorial:
安卓应用的安全和破解
tutorial's source code on github: crifan/android_app_security_crack: 安卓应用的安全和破解
Below ONLINE tool:
http://www.javadecompilers.com/apk
it do ALL by one click: decompiled .java files + resources + xml (in one .zip file) with very good decompiler (jadx return java code in places/functions where other compiles return comments inside function like "unable to decompile" or some android assembler/machine code)
I'll show you other way to decompile the .apk files.
You can follow the first 2 steps from "prankul garg". So you have another opportunities:
Step 3':
Download the "JD-GUI", thats easy to found this one.
Open your .jar file in "jd-gui.exe". (File > Open file > 'found your .jar file'). After this procedure, you can save all resources in a .zip file.
So,
1st - You have to rename the .apk file to .zip
2nd - You have to decode .dex file (if you want, decode the .apk file to dex2jar, that's possible)
3rd - You have to decode .jar file with JD-GUI
Apktool for reverse engineering 3rd party, closed, binary Android apps.
It can decode resources to nearly original form and rebuild them after making some modifications.
It makes possible to debug smali code step by step. Also it makes working with an app easier because of project-like file structure and automation of some repetitive tasks like building apk, etc.
http://ibotpeaches.github.io/Apktool/
apktool is THE way to go.
Online apktool service exists as well: http://www.javadecompilers.com/apktool
Some limitations, obviously, exist due to the service ‘online nature’: you may extract and research assets and the manifest file, but it is impossible to recompile the application at the moment.
Still, this is a no-hassle way to 'open' the android application.
You can try DexPatcher. It even integrates with Android Studio. It uses Apktool and Dex2Jar internally.
You can use those tools independently as well.
Apktool decompiles apk, and extracts .dex files, which can further be converted to jar using Dex2Jar. Jar can be decompiled by using JD-GUI. You can see the Java code with the help of that tool. Although the similarity of decompiled code to the actual code cannot be guaranteed. There are some advanced code obfuscation tools available in the market, which mess up the code to make it difficult to decompile / understand. eg. Proguard
Android studio offers you to analyse any apk file.
1 - From build menu choose analyse apk option and select apk file.
2 - This will result in you the classes.dex file and other files.
3 - Click on classes.dex which will give you the list of folders, packages, libraries and files.
4 - From and android studio settings install a plugin called "Dex to Jar"
5 - click on any activity file of your extracted project and choose dex to jar from the build menu.
This will result in you the actual code of your java file.
Cheers.
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 https://github.com/pxb1988/dex2jar/releases/tag/2.0 : dex2jar-2.0
Now open command prompt and change directory to that folder (or NEW FOLDER). Then execute :
d2j-dex2jar.bat classes.dex
Download this decompiler http://java-decompiler.github.io/ to decompile classes-dex2jar.jar
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 (https://ibotpeaches.github.io/Apktool/install/) 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 next
apktool 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.
Copycontents of both folders to a single folder
Done !
In order to decompile APK and get the code from it you have multiple online tools & I usually prefer to use Online APK Decompiler.
It is very easy to use and within few minutes you will be able to download the source code from it.
If you want to download APK from playstore and decompile. you can easily download it from it too.
The simplest way is using Apk OneClick Decompiler. That is a tool package to decompile & disassemble APKs (android packages).
FEATURES
All features are integrated into the right-click menu of Windows.
Decompile APK classes to Java source codes.
Disassemble APK to smali code and decode its resources.
Install APK to phone by right-click.
Recompile APK after editing smali code and/or resources.
During recompile:
Optimize png images
Sign apks
Zipalign
REQUIREMENTS
Java Runtime Environment (JRE) must be installed.
You can download it from this link Apk OneClick Decompiler
Enjoy that.
I found the following as the simplest method:
Rename your app.apk to app.zip (Change extension from apk to zip)
Extract the zip file into a folder
Use JADX tool to read the source code, present in classes.dex file.
There's an app for that and generally takes just a few clicks and you are done.
https://github.com/Nuvolect/DeepDive-Android
Select Apps, under "Installed Apps" select your app. If it is not
there you can load the APK.
Select "Extract APK"
Select "Unpack APK"
Select "Decompile with Jadx". This can take a few seconds or a few minutes depending
on the speed of your device
After that you can browse the source code, download it to another computer with elFinder or search through it using Lucene.
In addition to Jadx it has CFR and Fernflower decompilers.
I developed a Tool - Code Analyzer, it runs in iPhone/iPad/Mac, to analyze Java/Android files, https://decompile.io
1. Extracting the source from a native Android application
The source code of a native Android application is not difficult to obtain, but it does require extra tools that are compatible with Windows, Mac, and Linux. My personal favorites when it comes to tools are dex2jar and JD-GUI.
If you’re unfamiliar with these tools, dex2jar will read Dalvik Executable files and convert them to the standard JAR format. JD-GUI will read JAR files and decompile the class files found in them.
To make the extraction process easier to understand, let’s start by creating a fresh native Android project:
android create project --target 19 --name TestProject --path . --activity TestProjectActivity --package com.nraboy.testproject
The above command will leave you with an Android project in your current command prompt path.
Since our project has an Activity class already included, lets jump straight into the build process. You can give me a hard time all day long about using Ant instead of Gradle or Maven, but for this tutorial I’m going to stick with it.
ant debug
The above command will create a debug build typically found at bin/TestProject-debug.apk.
Using your favorite unzip tool, extract the APK file. 7-zip is a popular tool, but if you’re on a Mac you can just run the following from the Terminal:
unzip TestProject-debug.apk
This will leave us with a bunch of files and folders, but one is important to us. Make note of classes.dex because it contains all of our source code. To convert it into something readable we need to run dex2jar on it. You can use dex2jar on Mac, Linux, and Windows, but I’m going to explain from a Mac perspective.
With the classes.dex file in your extracted dex2jar directory, run the following from the Terminal:
./dex2jar.sh classes.dex
Open the JD-GUI application that you downloaded because it is now time to decode the JAR and packaged class files. Open the freshly created classes_dex2jar.jar file and you should see something like the following:
See how easy it was to get to the source code of your native Android APK? Now what can you do to better protect yourself?
The Android SDK ships with Proguard, which is a obfuscation module. What is obfuscation you ask?
Obfuscation via Wikipedia:
Obfuscation (or beclouding) is the hiding of intended meaning in
communication, making communication confusing, willfully ambiguous,
and harder to interpret.
While obfuscation will not encrypt your source code, it will make it more difficult to make sense of. With Proguard configured, run Ant in release mode and your code should be obfuscated on build.
2. Extracting the source from a hybrid Android application
The source code of hybrid applications are by far the easiest to extract. You don’t need any extra software installed on your computer, just access to the APK file.
To make things easier to understand, lets first create a fresh Apache Cordova project and then extract it. Start by doing the following:
cordova create TestProject com.example.testproject TestProject
cd TestProject
cordova platform add android
During the project creation process you are left with the default Apache Cordova CSS, HTML, and JavaScript templates. That is fine for us in this example. Let’s go ahead and build our project into a distributed APK file:
cordova build android
You’re going to be left with platforms/android/ant-build/CordovaApp-debug.apk or something along the lines of platforms/android/ant-build/*-debug.apk.
Even though this is a debug build, it is still very usable. With 7-zip or similar installed, right click the APK file and choose to extract or unzip it. In the extracted directory, you should now have access to all your web based source files. I say web based because any Java files used by Apache Cordova will have been compiled into class files. However, CSS, HTML, and JavaScript files do not get touched.
You just saw how depressingly easy it is to get hybrid application source code. So what can you do to better protect yourself?
You can uglify your code, which is a form of obfuscation.
Doing this will not encrypt your code, but it will make it that much more difficult to make sense of.
If you want to uglify your code, I recommend you install UglifyJS since it is pretty much the standard as of now. If you prefer to use a task runner, Grunt and Gulp have modules for UglifyJS as well.
There are lots of applications and methods in the market to decompile the apk file into java class but if the app is compiled with ProGuard rule then you are in a big trouble because this rule will shrink all the dex files into a small character name and then you can not trace back the implementation. see https://developer.android.com/studio/build/shrink-code for mode clarification.
Happy Coding...
Single click solution (Windows only)
after reading this loooooonnnnnngggg post,
i have decided to create an automated process to decompile APKs in a single click,
i have decided to share it on github:
https://github.com/shaybc/apk-decompiler
simply unzip,
copy the apk you want to decompile into "apk-source" folder
and run "go.bat"
find the result in the: "apk-output" folder
thats it, enjoy
I've been driving myself crazy for days trying to get dex2jar to work on a fedora 31 laptop against an apk that just wasn't going to work. This python 3 script did the trick in minutes and installing jd-gui made class files human readable.
http://java-decompiler.github.io/
https://github.com/Storyyeller/enjarify
specifically, here's what I ran:
# i installed apktool before the rest of the stuff, may not need it but here it is
$> cd /opt
$> sudo mkdir apktool
$> cd apktool/
$> sudo wget https://raw.githubusercontent.com/iBotPeaches/Apktool/master/scripts/linux/apktool
$> sudo wget https://bitbucket.org/iBotPeaches/apktool/downloads/apktool_2.4.1.jar
$> sudo mv apktool_2.4.1.jar apktool.jar
$> sudo mv apktool* /usr/bin/
$> sudo chmod a+x /usr/bin/apktool*
# and enjarify
$> cd /opt
$> sudo git clone https://github.com/Storyyeller/enjarify.git
$> cd enjarify/
$> sudo ln -s /opt/enjarify/enjarify.sh /usr/bin/enjarify
# and finally jd-gui
$> cd /opt
$> sudo git clone https://github.com/java-decompiler/jd-gui.git
$> cd jd-gui/
$> sudo ./gradlew build
# I made an alias to kick of the jd-gui with short commandline rather than long java -jar blahblahblah :)
$> echo "jd-gui='java -jar /opt/jd-gui/build/launch4j/lib/jd-gui-1.6.6.jar'" >> ~/.bashrc
Now one should be able to rum the following to get class files:
$> enjarify yourapkfile.apk
And to start jd-gui:
$> jd-gui
Then just open your class files!
Use this tool
http://www.javadecompilers.com/
But recently, a new wave of decompilers has forayed onto the market: Procyon, CFR, JD, Fernflower, Krakatau, Candle.
Here's a list of decompilers presented on this site:
CFR -
Free, no source-code available, http://www.benf.org/other/cfr/
Author: Lee Benfield
Very well-updated decompiler! CFR is able to decompile modern Java features - Java 9 modules, Java 8 lambdas, Java 7 String switches etc.
It'll even make a decent go of turning class files from other JVM langauges back into java!
JD -
free for non-commercial use only, http://jd.benow.ca/
Author: Emmanuel Dupuy
Updated in 2015. Has its own visual interface and plugins to Eclipse and IntelliJ . Written in C++, so very fast. Supports Java 5.
Procyon -
open-source, https://bitbucket.org/mstrobel/procyon/wiki/Java%20Decompiler
Author: Mike Strobel
Fernflower -
open-source, https://github.com/fesh0r/fernflower
Author: Egor Ushakov
Updated in 2015. Very promising analytical Java decompiler, now becomes an integral part of IntelliJ 14. (https://github.com/JetBrains/intellij-community/tree/master/plugins/java-decompiler)
Supports Java up to version 6 (Annotations, generics, enums)
JAD -
given here only for historical reason. Free, no source-code available, jad download mirror
Author: Pavel Kouznetsov
Yes, it is possible.
There are tons of software available to reverse engineer an android .apk file.
Recently, I had compiled an ultimate list of 47 best APK decompilers on my website. I arranged them into 4 different sections.
Open Source APK Decompilers
Online APK Decompilers
APK Decompiler for Windows, Mac or Linux
APK Decompiler Apps
I hope this collection will be helpful to you.
Link: https://www.edopedia.com/blog/best-apk-decompilers/

Selecting Android API level in Qt QMake

I'm using Qt 'qmake' from the command line (no use of QtCreator) am building for an Android target. No matter what I do it seems to use Android API level 9 in the Makefile it generates. Is there a command-line option, environment variable, or other method I can use to tell qmake to use a specific Android API level. I've been searching for a long time and cannot find anything.
Change environment to ANDROID_NDK_PLATFORM=android- the api-level you want or in QtCreator->Project->Build Environment->Add/update the above variable.
To choose a specific minimum API level, you need to provide your own Android manifest file.
I know you're not using Qt Creator, but it supports this by being able to generate a new manifest file from a template.
More details available from the Qt Docs on deploying to Android:
http://doc.qt.io/qtcreator/creator-deploying-android.html
You can specify settings for the androiddeployqt tool in Qt Creator and in the project .pro file. To specify settings in Qt Creator, select Projects > Build Android APK > Details.
...
You can use the qmake variables to specify all the settings you need for the androiddeployqt tool and you do not need an Android manifest file until you want to publish the package in an application store. To specify additional settings for APK packages, you can create an Android manifest file and edit it in Qt Creator. Select Create Templates to create the file and to open it in the Android Manifest Editor.
If you're not using Qt Creator you'll presumably need to generate an Android manifest file manually and place it in your source directory. androiddeployqt should pick it up.
ANDROID_PACKAGE_SOURCE_DIR: This variable can be used to specify a directory where additions and modifications can be made to the default Android package template. The androiddeployqt tool will copy the application template from Qt into the build directory, and then it will copy the contents of the ANDROID_PACKAGE_SOURCE_DIR on top of this, overwriting any existing files.
...
If you, for instance, want to make a custom AndroidManifest.xml for your application, then place this directly into the folder specified in this variable.
...
Note: When adding custom versions of the build files (like strings.xml, libs.xml, AndroidManifest.xml, etc.) to your project, make sure you copy them from the package template, which is located in $QT/src/android/java. You should never copy any files from the build directory, as these files have been altered to match the current build settings.

How do I use Ant to build multiple Android APKs with the same code base, but with different resource files?

I am trying to build a branded Android app, that will have different resource files (mainly drawables) for different customers. The Java code in the apps will be the same, but the different apps will have a different look--meaning different color schemes and different logos etc. I have been told, and my research suggests that Ant is the best way to achieve this.
Where should I change the Android 'build.xml' file? What sort of Ant task should I use to achieve this?
For debugging, I would like to just use Eclipse and build with the default resources. But for production releases, I would like to run Ant on build.xml to produce multiple APKs from different /res folders. I do not even need any code snippets (although that would be nice), just even some tips from people that have done this before or something similar.
I ended up writing a Python script to reorganize the Android project before each build. I recommend avoiding the use of Ant for stuff like this. My 100-200 lines of Python achieved the equivalent of about 1000+ extra lines of Ant that was required in addition to the default Android build.xml Ant script.
I have encountered a similar issue where I want to compile the same code base with some changes as well as changes in the resource files. The solution I am pursuing at the moment is creating a library with the shared code/resources and separate "regular" projects for each of the different APK releases. Unfortunately, I don't have a functional final solution to the problem yet, so all I can give is these vague hints.
Requirement Setup
1. Go to the URL :
http://ant.apache.org/bindownload.cgi
and download the apache ant and extract it in to the any folder like d:/ant .
2. I think you already having the Android SDK path is like(D:/Android SDK/)
Now go to the Enviroment variables and check whether path variable is there is there add these in path otherwise create a new varible with name path and put it there in vaue
D:/ant/bin;D:/Android SDK/tools
done
Go to command prompt and navigate it to the root directory of your project and run the command
android update project -p /
Note: / if you are in the root directory of project else you need to give the path of root directory like d:/myworkspace/mysampleproject
this will generate and build.xml file in your project.
now run the command for this it is necessary to be in root directory of your project
ant debug
this will generate an apk file in bin folder signed with default debug key.

Renaming the Package Name inside an APK

I have created an AIR app that is currently on the market. To update the app, obviously I must keep the same package name. My first version's were packaged using Eclipse with the ADT plugin.
Now to use AIR 3.0 Native Extensions (ANE) which were not available when I first developed the app, I currently must create my APK using AIR's command line tools. Unfortunately, these command line tools force you to have a package name that starts with the word "air". For example, I need the package name "com.example". AIR creates the package name as "air.com.example".
So now, I cannot update my app in the market since the package name has changed. Adobe has this horrific article to help you rename and remove the "air" in the package. I'm not a great programmer so this has really stumped me.
http://kb2.adobe.com/cps/875/cpsid_87562.html
Apparently this info is out of date or incorrect in a few areas.
I have completely stumbled at step 12 which uses apkbuilder:
apkbuilder final.apk -u -z resources.arsc -f classes.dex
I am getting this error message:
THIS TOOL IS DEPRECATED. See --help for more information.
java.io.FileNotFoundException: resources.arsc does not exist
I have used step 10 to create the new resources.arsc file. It clearly DOES exist and in the correct location. I tried using apkbuilder with other resources.arsc files taken from other projects. I still get the same error message.
Is there a chance in hell of this working? If anyone is interested in this, I have a zip file with a sample AIR apk, windows bat files for all the command line work, and all the needed utilities so they don't need to be downloaded. To get started you just need to change my path.bat to fit your system. And you need notepad++ (or an equivalent) to batch automate renaming the package name across several files.
bradwallacedesign.com/dktimer/renameApkProject.zip
Thanks so much!
this was done on a pc. i have no idea how to do this on a mac.
i don't recommend using this to remove the "air." from an air package name. If you do so, the user will not be prompted to download air on their device. the user will get an error message instead with no clue to the problem. of course you can use air captive runtime to solve this issue.
http://bradwallacedesign.com/share/renameAPK.zip
download and unzip my file (renameAPK.zip) to c:\renameAPK.
required files:
my file (renameAPK.zip) which contains the apkTool
java jdk/jre
android SDK
notepad++ (or an equivalent text editor that can rename across multiple files)
i made many bat files since i'm not sure how to combine them into one file. you will need to edit each one to change your path names and file names to work with your computer and your apk file.
i numbered all the bats in the order that i use them. once a command line is open, i type the number of the bat file i want then hit the tab key to automatically finish the name of the bat file then hit enter to run that bat file.
instructions:
double click `openCmd.bat to open a command line pointing to the directory with all your files.
0. run 0path.bat to set your path. (i can't remember now if the adobe air sdk is needed for this but i have it in my path. obviously, the JDK is needed and the android sdk for the jarsigner and zip align i think.)
1. run 1decompileAPK.bat to have apkTool decompile your app into a folder called UNZIPPEDapk
2. follow the instructions in 2editManifest & PackageName - Instructions (not a bat).txt to edit the manifest and package name using Notepad++ inside UNZIPPEDapk:
edit AndroidManifest.xml:
a. change package name from air.oldPackageName to newPackageName
b. edit other needed entries:
c. rename folder system inside "smali" folder so that it works with your new package name
for example:
if the old package name was: air/oldName then change the folders to match the new package name: air/newName
use notepad++ (or any editor that can find and replace text over many files)
d. ctrl+shift+f --- "Find in files"
find:
air/oldPackageName
replace with:
newPackageName
where:
all files in UNZIPPEDapk/smali
(i think there were over 200 replacements)
3. run 3buildDistFolder.bat to have apkTool build the new apk in the UNZIPPEDapk\Dist folder
4. follow the instructions in 4getMissingFiles - instructions.txt to reinstate the 2 missing files in the new build:
a. Two files were not built during 3buildDistFolder:
3buildDistFolder.bat built the new apk in the \UNZIPPEDapk\dist folder but it failed to copy 2 files:
(skipping hidden file 'C:\Users\computer\apkTool\UNZIPPEDapk\assets\META-INF
\AIR\extensions\com.adobe.mobile\META-INF\ANE\Android-ARM.classpath')
(skipping hidden file 'C:\Users\computer\apkTool\UNZIPPEDapk\assets\META-INF
\AIR\extensions\com.adobe.mobile\META-INF\ANE\Android-ARM.project')
grab these 2 files from your original apk and drop them into your new apk in the correct folder
b. copy yourApp.apk from DKTimer/Dist/ to root directory where your bat files are.
5. run 5signAPK.bat to sign the apk.
developer.android.com/guide/publishing/app-signing.html
6. run 6verifySigned.bat to verify the signing worked properly
7. run 7zipAlign.bat to align the apk file.
developer.android.com/guide/developing/tools/zipalign.html
You are finished at this point. Continue on if you want to test it on a device.
8. run 8installAPK.bat to install the apk on a usb connected device.
9. run 9remoteDebugger.bat if you want to use remote debugging.
i hope this helps someone. let me know if i forgot to include something.
also, if you know a better way to do this, please comment (such as how to combine this into 1 long pausing bat file...)
There is a simple environment variable you can set to disable the air. prefix easily. The following code exists in the Adobe AIR packager:
String optOut = System.getenv("AIR_NOANDROIDFLAIR");
if ((optOut == null) || (optOut.indexOf("true") == -1)) {
packageName = "air." + packageName;
}
So, simply set the AIR_NOANDROIDFLAIR environment variable to true, repackage your application, and it won't have the air. prefix. Google how to set environment variables in windows or mac for your particular OS version.
For example, I use the command-line compiler on Mac/Linux, so I run:
> export AIR_NOANDROIDFLAIR=true
> java -jar $AIR_HOME/lib/adt.jar -package -target apk-captive-runtime -storetype pkcs12 -keystore cert.p12 -storepass *** Main.apk Main-app.xml Main.swf
Warning: I don't know what implications this has. Per someone's note above, this may only be a good idea with captive runtime (but that's the default going forward from AIR 3.8).
Update: Renaun Erickson said it shouldn't cause problems.
Cross-posted here (slightly different question, same answer).
Having tried several apkRename tools, I found that they all failed for some app, such as com.android.browser on HTC device.
The reason is in apktool which does not correctly unpack apk file sometimes.
So, i create my own tool: https://github.com/sjitech/ApkRename
No need apktool, no need aapt, just java and jar utilities.
This utility directly modify AndroidManifest.xml so without recompile whole resource by apktool,
so it's clean.
Tested devices: 11 kinds (both android 4+, but 2.2+ should be no OK)
Tested OS: Mac OS X 10.9 and CentOS 6. (Cygwin with bash 4+ should be OK, but not tested yet)
I actually tried brad's approach and couldn't imagine having to go through the process EVERY TIME i compiled a release. so i did something else...i modified ADT so it doesn't insert "air." at the start and replaces it with a more useful extension like "com."
Here's a summary of the approach:
use:
jar xf adt.jar
to extract the adt.jar file to a directory on your desktop. you'll find it in {adobe SDK}/lib/
look for the file APKOutputStream.class
com/adobe/air/apk/APKOutputStream.class
Open it in a hex editor (eg, HxD is what i used). Search for "air." (without the quotes but including the dot).
Don't delete the entry. i tried, you can't, it corrupts the class and it won't run. What you can do, however, is replace "air." with "com." because it has the same number of characters and doesn't mess with the length of the file. The com prefix is a lot more useful to most of us.
save the modified APKOutputStream.class file and repackage with JAR. something like this:
jar cfm ..\patchedadt.jar ..\MANIFEST.MF *
you'll want to copy that MANIFEST.MF file from the subdirectory of the package called META-INF
Rename your patchedadt.jar to adt.jar and put it back in the lib directory. Works with the Flash Builder and all that garb.
Needless to say, when you're in there, you'll want to produce your package without a "com." prefix so you don't end up with com.com.your.package.name.
maybe there was an easier way, but i didn't know any better and no one else had an answer except to decompile the apk, modify it, and recompile and that didn't even work. so i figured i'll share what i did in case someone else stumbles on it later :)
jim

Categories

Resources