Is there any way to generate an apk file from an Android Application Bundle (aab) via Terminal or using Android Studio?
So far nobody has provided the solution to get the APK from an AAB.
This solution will generate a universal binary as an apk.
Add --mode=universal to your bundletool command (if you need a signed app, use the --ks parameters as required).
bundletool build-apks --bundle=/MyApp/my_app.aab --output=/MyApp/my_app.apks
--mode=universal
MAIN STEP: Change the output file name from .apks to .zip
Unzip and explore
The file universal.apk is your app
This universal binary will likely be quite big but is a great solution for sending to the QA department or distributing the App anywhere other than the Google Play store.
By default, the IDE does not use app bundles to deploy your app to a
local device for testing
Refer bundletool command
For Debug apk command,
bundletool build-apks --bundle=/MyApp/my_app.aab --output=/MyApp/my_app.apks
For Release apk command,
bundletool build-apks --bundle=/MyApp/my_app.aab --output=/MyApp/my_app.apks
--ks=/MyApp/keystore.jks
--ks-pass=file:/MyApp/keystore.pwd
--ks-key-alias=MyKeyAlias
--key-pass=file:/MyApp/key.pwd
Edit:
I have been using following commands while testing my release build for aab:
Download bundletool jar file from Github Repository (Latest release > Assets > bundletool-all-version.jar file). Rename that file to bundletool.jar
Generate your aab file from Android Studio eg: myapp-release.aab
Run following command:
java -jar "path/to/bundletool.jar" build-apks --bundle=myapp-release.aab --output=myapp.apks --ks="/path/to/myapp-release.keystore" --ks-pass=pass:myapp-keystore-pass --ks-key-alias=myapp-alias --key-pass=pass:myapp-alias-pass
myapp.apks file will be generated
Make sure your device is connected to your machine
Now run following command to install it on your device:
java -jar "path/to/bundletool.jar" install-apks --apks=myapp.apks
Edit 2:
If you need to extract a single .apk file from the .aab file, you can add a extra param --mode=universal to the bundletool command:
bundletool build-apks --bundle=/MyApp/my_app.aab --output=/MyApp/my_app.apks \
--mode=universal \
--ks=/MyApp/keystore.jks \
--ks-pass=file:/MyApp/keystore.pwd \
--ks-key-alias=MyKeyAlias \
--key-pass=file:/MyApp/key.pwd
and execute
unzip -p /MyApp/my_app.apks universal.apk > /MyApp/my_app.apk
this will generate a single a /MyApp/my_app.apk file that can be shared an installed by any device app installer
Ok here is the complete way I had to do:
Download bundletool-all-0.10.3.jar from this link, download the latest version available
Create an app bundle using android studio and locate its path:
In my case its E:\Projects\Android\Temp\app\build\outputs\bundle\debug\app.aab
Copy the bundletools jar to some location and get its path
In my case its E:\Temp\bundletool-all-0.6.0.jar
Use this command:
java -jar "BUNDLE_TOOL_JAR_PATH" build-apks --bundle="BUNDLE_PATH" --output=YOUR_OUTPUT_NAME.apks
In my case it will be
java -jar "E:\Temp\bundletool-all-0.6.0.jar" build-apks \
--bundle="E:\Projects\Android\Temp\app\build\outputs\bundle\debug\app.aab" \
--output=out_bundle_archive_set.apks
This will create a file out_bundle_archive_set.apks , rename it to .zip out_bundle_archive_set.zip , extract this file and done You will have multiple apk files
To install directly on external device use :
java -jar "E:\Temp\bundletool-all-0.6.0.jar" install-apks --apks=out_bundle_archive_set.apks
Check this blog post for more info . also check out official site
People have already explained on how to do this with the command-line. For completion, I thought I'd also show the way to do it via the UI in Android Studio.
When you open your "Run/Debug Configurations", you can select "APK from app bundle" (instead of "Default APK").
See screenshot:
Refer Geek Dashboard for more info.
For those who are looking to generate a single universal APK file from your Android App Bundle, you must use --universal flag while running the build-apks command.
java -jar bundletool.jar build-apks --bundle=your_app.aab --output=your_app.apks --mode=universal
Where
bundletool.jar is the bundletool jar file you downloaded here
your_app.aab is the Android App Bundle of your App
your_app.apks is the output APKs Archive File that will be generated once you run the command.
While running the above command make sure you place bundletool.jar and your AAB file in the same folder.
Now, you need to change the your_app.apks file format to your_app.zip and extract it to find the universal.apk file
Note: Use –overwrite flag to overwrite the APKs file if there is already one with the same name. Otherwise, bundletool command will throw you a fatal error.
on mac it can be easily done using homebrew
brew install bundletool
you can use the command below to generate apks
bundletool build-apks --bundle=aab_path.aab --output=release.apks
above command generates apks file which can later be extracted to give various apk files. To see all generated files change the extension from .apks to .zip and just extract the files.
then you can install apk using this command on connected device
bundletool install-apks --apks=release.apks
There's a tool called bundletool, which can create APK's out of your AAB file:
Find details about this tool here: https://developer.android.com/studio/command-line/bundletool
But here some highlights taken from that site:
Building APKs
When bundletool generates APKs from your app bundle, it includes them in a container called an APK set archive, which uses the .apks file extension. To generate an APK set for all device configurations your app supports from your app bundle, use the bundletool build-apks command, as shown below:
bundletool build-apks --bundle=/MyApp/my_app.aab --output=/MyApp/my_app.apks
Note that the command above creates an APK set of unsigned APKs. If you want to deploy the APKs to a device, you need to also include your app’s signing information, as shown in the command below.
bundletool build-apks --bundle=/MyApp/my_app.aab --output=/MyApp/my_app.apks
--ks=/MyApp/keystore.jks
--ks-pass=file:/MyApp/keystore.pwd
--ks-key-alias=MyKeyAlias
--key-pass=file:/MyApp/key.pwd
Installing APKs
bundletool install-apks --apks=/MyApp/my_app.apks
Generate a device-specific set of APKs
bundletool build-apks --connected-device --bundle=/MyApp/my_app.aab --output=/MyApp/my_app.apks
I have developed a windows tool for converting .aab files to .apk in Python.
It supports creating both debug and signed apk which can be directly installed to default android device connected through USB.
It uses google’s bundle tool in the backend.
https://aabtoapkconverter.com/
Edit:
The Source code is now available now on github.
This is first tool that I have developed and shared with the world. Hope it is useful. I am open to suggestions and bug reports.
Here is what i did.
First thing is, i am on a Mac.
So in this official guide https://reactnative.dev/docs/signed-apk-android, followed below steps.
Run this command sudo keytool -genkey -v -keystore my-upload-key.keystore -alias my-key-alias -keyalg RSA -keysize 2048 -validity 10000
you can change the name of my-upload-key to your choice
Setup the gradle variables as per the guide
Also do the same as per the guide for point "Adding signing config to your app's Gradle config"
Now rather than continuing (which will generate an AAB file) what you can do is below.
4.1 I open the same project(android folder) in Android Studio
4.2 From the Menu Options > Build > Clean Project
4.3 Click on the Make Project button and let it complete (if you can run using npm run android, then this should finish without any issues)
Make Project
4.4 Once done, click on Menu options > Build > Generate Signed Bundle/APK...
Generate Signed Bundle/APK...
4.5 In the next Screen Choose APK radio button and Click Next
Choose APK option
4.6 In the next screen, Browse to the keystore file which you generated as the first step, its password, alias name and its password, click Next.
Final Step
Wait for it to complete. You may see some errors but more importantly in the end you should get a popup in the right bottom corner saying "Locate". Click on that and you will find your app-release.apk.
I think this method much more efficient
The goal here is to copy and paste downloaded Android SDK packages to multiple computer and run ./sdkmanager 'xxx' to install them locally (with no access to dl.google.com).
I tried ~/Library/Android/sdk/temp and ~/.android/tmp with no luck.
On linux it is in /tmp/PackageOperationX where X is a number.
MacOS
commandline sdkmanager
the temporary files will be downloaded to /private/var/folders/ when regular professional users couldn't comprehend how this decision can be made by developers of this commandline tool and MacOS, and still not informing their users in documentation
For example, to find out the file while sdkmanager is downloading the package system-images;android-29;google_apis;x86_64, with zip file named "x86_64-29_r11.zip":
lsof | grep x86_64-29_r11.zip
## output
java 5422 username 35w REG 1,7 408368096 19062984 /private/var/folders/t7/z9lknwrd31q55t9m7s4qhm140000gp/T/PackageOperation02/x86_64-29_r11.zip
Using find also can work, but if you are searching for / it will take longer, so you can try on /private directly
sudo find / -name "*x86_64-29_r11.zip*" 2> >(grep -v 'Operation not permitted' >&2)
sudo find /private -name "*x86_64-29_r11.zip*" 2> >(grep -v 'Operation not permitted' >&2)
Source for coming up with the solutions:
See what process is using a file in Mac OS X
How can I exclude all "permission denied" messages from "find"?
Android Studio SDK Manager
the location for temporary storage of packages downloaded is $HOME/Library/Android/sdk/.downloadIntermediates and will be moved to $HOME/Library/Android/sdk/.temp/PackageOperation0X for extracting operation where X is a number. These packages will be deleted once they are extracted to their respective directories.
i want to decompile my recent apk to test is it.
i run the code
C:\Users\admin\apktool d OwnApp.apk
but it's getting error with :
Input file (OwnApp.apk) was not found or was not readable.
why am i getting this?
Procedure for decoding .apk files, step-by-step method:
Step 1:
1). Make a new folder and copy over the .apk file that you want to decode.
2). Now rename the extension of this .apk file to .zip (e.g. rename from filename.apk to filename.zip) and save it.
3). 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:
1). Now extract this .zip file in the same folder (or NEW FOLDER).
2). Download dex2jar and extract it to the same folder (or NEW FOLDER).
3). Move the classes.dex file into the dex2jar folder.
4). Now open command prompt and change directory to that folder (or NEW FOLDER). 5). Then write d2j-dex2jar classes.dex (for mac terminal or ubuntu write ./d2j-dex2jar.sh classes.dex) and press enter.
6). You now have the classes.dex.dex2jar file in the same folder.
7). 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.
8). 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:
1). Now open another new folder
2). Put in the .apk file which you want to decode
3). 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
4). Open a command window apktool d myApp.apk (where myApp.apk denotes the filename that you want to decode)
5). now you get a file folder in that folder and can easily read the apk's xml files.
this solutions is extracted from this StactOverflow site Check Here
you can download all the required libraries from here libraries
Recompiling apk using apktool for MAC:-
Process to DeCompile APK(Android Package):
Open terminal and cd to apk directory
type su
apktool d <../../pathToMyAPK>
Process to ReCompile APK(Android Package):
Open terminal and cd to apk directory
type su
apktool b <../../pathToMyAPKFolder>
New apk is generated in pathToMyAPK/dist/NewAPP.apk
->Now we need to sign the apk to be able to port to device.
To sign an apk:
jarsigner -verbose -keystore <path of my-keystore.keystore> <path of apk> alias_name
For Decompile, Run Apktools Over CMD like C:\\example: apktool d x.apk
I use livecode for developed. My project larger than 50MB. It's can't publish to google play store. So I build standalone application without resource files. And I create obb file with jobb.
Step by Step
My project package name is com.tester.guru Version name is 3.0 and Version code is 3
I set signing to "Sign for development only" (for simple install application to my device.)
I set install location to "Allow External Storage"
I create obb file with jobb. Command below:
jobb -d resources directory -o main.3.com.tester.guru.obb -k guruasean -pn com.tester.guru -pv 3
Now I have 2 files:APK file and main.3.com.tester.guru.obb file
Copy the installation file (.apk) to the SD Card and Install it.
Copy the obb file to /Android/obb/
After I do 7 steps and run application. It not show image because image wrong path.
How do I do for solve this problem.
I have an android apk and I deleted my source code and dont have the project again, I want to change the version code of the old apk. my question is how do I unzip and repack the apk so I can use the. am using a mac system. I saw so many things for windows but i couldnt find for mac.I need help please
unzip apk files
The simplest method is executing unzip command:
unzip xxx.apk -d xxx
A directory xxx will be generated to store unzipped files.
Actually, .apk files are same as .zip files. Execute command file XXX.apk to see that.
get readable text files from apk
If you want readable text files such as the manifest file, I would suggest you to use the apktool. We could install the apktool easily with Homebrew:
brew install apktool
then get the readable text files:
apktool d xxx.apk
after the previous command, a xxx directory contains readable text files and others would be there.
edit zip files
If you want to edit a zip file in place, the Keka might be a good option.
To give a complete answer for unpacking, editing and packing on Mac:
Unpacking / Unzipping
As Liu Tao stated, the easiest way to unpack a *.apk file on mac is to use the following command:
unzip xxx.apk -d xxx
This is because an *.apk file is nothing else than a zip file. Again, as Liu Tao stated, this can be found out with the file command.
file xxx.apk
Which will show an output that looks something like this:
xxx.apk: Zip archive data, at least v2.0 to extract
Editing
I think this is self-explanatory. Go into the folder to which you exported the *.apk contents and edit them as you would usually do.
Packing / Zipping
On Mac, this is also quite straight-forward.
You can use the zip command to pack all the files back into an *.apk file.
zip -r xxx.apk xxx/
You want to use APKTool. It will handle the unzip and rebuild for you: http://ibotpeaches.github.io/Apktool/