Related
I built my project using the new Android App Bundle format. With APK files, I can download the APK to my device, open it, and immediately install the app. I downloaded my app as a bundle (.aab format) and my Nexus 5X running Android 8.1 can't open the file. Is there any way to install AABs on devices in the same convenient manner as APKs?
Short answer:
Not directly.
Longer answer:
Android App Bundles is the default publishing format for apps on the Google Play Store. But Android devices require .apk files to install applications.
The Play Store or any other source that you're installing from will extract apks from the bundle, sign each one and then install them specific to the target device.
The conversion from .aab to .apk is done via bundletool.
You can use Internal App Sharing to upload a debuggable build of your app to the Play Store and share it with testers.
For MAC:
brew install bundletool
bundletool build-apks --bundle=app-release.aab --output=app-release.apks
bundletool install-apks --apks=app-release.apks
Installing the aab directly from the device, I couldn't find a way for that.
But there is a way to install it through your command line using the following documentation You can install apk to a device through BundleTool
According to "#Albert Vila Calvo" comment he noted that to install bundletools using HomeBrew use brew install bundletool
You can now install extract apks from aab file and install it to a device
Extracting apk files from through the next command
java -jar bundletool-all-0.3.3.jar build-apks --bundle=bundle.aab --output=app.apks --ks=my-release-key.keystore --ks-key-alias=alias --ks-pass=pass:password
Arguments:
--bundle -> Android Bundle .aab file
--output -> Destination and file name for the generated apk file
--ks -> Keystore file used to generate the Android Bundle
--ks-key-alias -> Alias for keystore file
--ks-pass -> Password for Alias file (Please note the 'pass' prefix before password value)
Then you will have a file with extension .apks
So now you need to install it to a device
java -jar bundletool-all-0.6.0.jar install-apks --adb=/android-sdk/platform-tools/adb --apks=app.apks
Arguments:
--adb -> Path to adb file
--apks -> Apks file need to be installed
If you want to install apk from your aab to your device for testing purpose then you need to edit the configuration before running it on the connected device.
Go to Edit Configurations
Select the Deploy dropdown and change it from "Default apk" to "APK from app bundle".
Apply the changes and then run it on the device connected. Build time will increase after making this change.
This will install an apk directly on the device connected from the aab.
You cannot install app bundle [NAME].aab directly to android device because it is publishing format, but there is way to extract the required apk from bundle and install it to you device, the process is as follow
Download bundletool from here
run this in your terminal,
java -jar bundletool.jar build-apks --bundle=bundleapp.aab --output=out_bundle_archive_set.apks
Last step will generate a file named as out_bundle_archive_set.apks, just rename it to out_bundle_archive_set.zip and extract the zip file, jump into the folder out_bundle_archive_set > standalones, where you will seee a list of all the apks
There goes the reference from android developers for bundle tools link
For those, who want single universal.apk that can run on every android device:
brew install bundletool
bundletool build-apks --mode universal --bundle ./app-release.aab --output ./app.apks
mv app.apks app.zip
unzip app.zip
Now, you can get your universal.apk
This worked for me on a mac.
You need to use a tool called bundletool You can install it incase if not already installed using brew
brew install bundletool
Run this command to extract and store the apks file at the desired location
bundletool build-apks --bundle=path/to/app-release.aab --output=/path/to/output/app.apks --local-testing
Install on a connected Android device
bundletool install-apks --apks=/path/to/output/app.apks
I have noted the complete command with output in a gist here https://gist.github.com/maheshmnj/6f5debbfae2b8183d94ca789d081f026
If you're using Maui at this point Visual Studio 2022 only creates AAB files; however, you can create an APK from a command line.
Change directory to where your project is located and run this:
dotnet publish -f:net6.0-android -c:Release /p:AndroidSigningKeyPass=blah
If you want to install the APP bundle without using PLAY STORE, You need to change your build variant to "release" at Android studio.
If you cannot build App yourself but have a release bundle, then refer to the most popular answer.
Go to Android Studio > Build > Select Build Variant..
Once you do this your build configuration may start showing errors.
This is because you now need to provide signing details in this configuration as well (this refers signing details from build.gradle)
you may either Edit the configuration and go to the Fix button at the bottom which will ask you to fill in signing details.
Or you may edit the build.gradle
Make sure you provide buildTypes {} and signingConfigs {}
android {
signingConfigs {
release {
storeFile file('<Your PATH>\\keystore.jks')
storePassword 'XXXXX
keyAlias 'XXXXX'
keyPassword 'xxxxx'
}
debug {
storeFile file('<Your PATH>\\keystore.jks')
storePassword 'XXXXX
keyAlias 'XXXXX'
keyPassword 'xxxxx'
}
}
compileSdkVersion 32
defaultConfig {
....
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
}
debug
{
signingConfig signingConfigs.debug
}
}
...
}
dependencies {
...
}
There is one or two minutes of delay before Android Studio starts reflecting correctly. Otherwise, you may do a clean rebuild and then run the app.
When you run the app this time it will be installed in release mode on the target device.
You may need a way to identify the Build Variant of the installed app. You may show the build name and variant somewhere in your app. Or if you have a button somewhere which shows only in debug mode you can check that.
If you have the project you can just build an app with android studio or push it directly to the device if you run a debug or release config with the device connected and selected as the target so long as you enable adb in developer mode on the device and tap trust this computer when you connect it to your machine.
But if you have the bundle because you're trying to install an app pulled from one phone onto another, there are free online services that convert play store links into a direct download of the apk. Just turn on add debugging on the device and adb install <path-to-apk> from the terminal.
If you have more than one device connected with adb enabled you can adb devices to get a list of their identifiers and adb install <path-to-apk> <device-id> will work as well. Or you can use adb to your advantage and do many things on multiple devices at once depending on your needs. There's even ways to adb over wifi.
You will need adb from the android-sdk tools to do any of this though, with Android Studio installed you would have a local installation already but it may not be in your path. However studios terminal likely has access to it since it would be the sdk path your IDE has saved in preferences.. If not you can download a standalone sdk/find out which one studio is using from it's preferences and either
Add adb from the platform-tools directory of said sdk it to your path (best)
Invoke adb from it's absolute path you just located and just keep hitting up to re-use your last command, swapping out the apk/device
cd to the adb directory and just use it with the full path to each of your apks (easiest)
For Windows 11:
PS C:/folder-with-aab-file> java -jar C:\dev\bundletool-all-1.9.1\bundletool.jar build-apks --bundle=app-release.aab --output=app-release.aab.apks --mode=universal
PS C:/folder-with-aab-file> ren app-release.aab.apks app-release.aab.apks.zip
After descompact zip file, the apk file'll with the name: universal.apk
Is there any way to install AABs on devices in the same convenient manner as APKs?
As installing is done by third party apps or mobile company file manager like apps.
The upcoming file managers versions, hence forth, will come with "aab" managing tools.
I searched "android aab installer" on playstore and found one.
deliberately not naming it.
The one I installed, extracted the bundle online,
But after that this app wasn't able to install this extracted app by itself (on my mi [miui] device ).
But this application saved the online extracted apk on phone memory, from where I was able to install it.
remember:
Google's "files" application wasn't able to install this apkbutmy system (in built) filer manager was able to.
Use (on Linux):
cd android
./gradlew assemblyRelease|assemblyDebug
An unsigned APK is generated for each case (for debug or testing)
NOTE: On Windows, replace gradle executable for gradlew.bat
I referred bundletool command after that I created APKs using the command prompt. But I can't install apk in the device.
My path of apk's file is- D:\testRelease\XYZ.aab
So I try this command to install:-
--> bundletool.jar install-apks --apks=D:/testRelease/XYZ.apks
but can't get any output. I also tried to get connected to device-spec but still can't get any output
As a precondition remember to create an environment variable "ANDROID_HOME" and set it to where the Android SDK is located on your Development machine.
So for Windows it may be
ANDROID_HOME = "C:/MyAndroid"
Assuming you are testing on just one device first generate the bundle only for your connected device using the following.
bundletool build-apks --connected-device --bundle="\somepath\app-release.aab" --output="\somepath\release.apks" --ks="somepath\keystore" --ks-pass=pass:cleartextpasswd --ks-key-alias=keyalias --key-pass=pass:cleartextpasswd
Note the use of the option
--connected-device
Now to install on a specific device use the following command:
bundletool install-apks --apks="somefolder\release.apks"
--device-id="yourdeviceidstring"
Get the device id string from the Settings section of your device.
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
I built my project using the new Android App Bundle format. With APK files, I can download the APK to my device, open it, and immediately install the app. I downloaded my app as a bundle (.aab format) and my Nexus 5X running Android 8.1 can't open the file. Is there any way to install AABs on devices in the same convenient manner as APKs?
Short answer:
Not directly.
Longer answer:
Android App Bundles is the default publishing format for apps on the Google Play Store. But Android devices require .apk files to install applications.
The Play Store or any other source that you're installing from will extract apks from the bundle, sign each one and then install them specific to the target device.
The conversion from .aab to .apk is done via bundletool.
You can use Internal App Sharing to upload a debuggable build of your app to the Play Store and share it with testers.
For MAC:
brew install bundletool
bundletool build-apks --bundle=app-release.aab --output=app-release.apks
bundletool install-apks --apks=app-release.apks
Installing the aab directly from the device, I couldn't find a way for that.
But there is a way to install it through your command line using the following documentation You can install apk to a device through BundleTool
According to "#Albert Vila Calvo" comment he noted that to install bundletools using HomeBrew use brew install bundletool
You can now install extract apks from aab file and install it to a device
Extracting apk files from through the next command
java -jar bundletool-all-0.3.3.jar build-apks --bundle=bundle.aab --output=app.apks --ks=my-release-key.keystore --ks-key-alias=alias --ks-pass=pass:password
Arguments:
--bundle -> Android Bundle .aab file
--output -> Destination and file name for the generated apk file
--ks -> Keystore file used to generate the Android Bundle
--ks-key-alias -> Alias for keystore file
--ks-pass -> Password for Alias file (Please note the 'pass' prefix before password value)
Then you will have a file with extension .apks
So now you need to install it to a device
java -jar bundletool-all-0.6.0.jar install-apks --adb=/android-sdk/platform-tools/adb --apks=app.apks
Arguments:
--adb -> Path to adb file
--apks -> Apks file need to be installed
If you want to install apk from your aab to your device for testing purpose then you need to edit the configuration before running it on the connected device.
Go to Edit Configurations
Select the Deploy dropdown and change it from "Default apk" to "APK from app bundle".
Apply the changes and then run it on the device connected. Build time will increase after making this change.
This will install an apk directly on the device connected from the aab.
You cannot install app bundle [NAME].aab directly to android device because it is publishing format, but there is way to extract the required apk from bundle and install it to you device, the process is as follow
Download bundletool from here
run this in your terminal,
java -jar bundletool.jar build-apks --bundle=bundleapp.aab --output=out_bundle_archive_set.apks
Last step will generate a file named as out_bundle_archive_set.apks, just rename it to out_bundle_archive_set.zip and extract the zip file, jump into the folder out_bundle_archive_set > standalones, where you will seee a list of all the apks
There goes the reference from android developers for bundle tools link
For those, who want single universal.apk that can run on every android device:
brew install bundletool
bundletool build-apks --mode universal --bundle ./app-release.aab --output ./app.apks
mv app.apks app.zip
unzip app.zip
Now, you can get your universal.apk
This worked for me on a mac.
You need to use a tool called bundletool You can install it incase if not already installed using brew
brew install bundletool
Run this command to extract and store the apks file at the desired location
bundletool build-apks --bundle=path/to/app-release.aab --output=/path/to/output/app.apks --local-testing
Install on a connected Android device
bundletool install-apks --apks=/path/to/output/app.apks
I have noted the complete command with output in a gist here https://gist.github.com/maheshmnj/6f5debbfae2b8183d94ca789d081f026
If you're using Maui at this point Visual Studio 2022 only creates AAB files; however, you can create an APK from a command line.
Change directory to where your project is located and run this:
dotnet publish -f:net6.0-android -c:Release /p:AndroidSigningKeyPass=blah
If you want to install the APP bundle without using PLAY STORE, You need to change your build variant to "release" at Android studio.
If you cannot build App yourself but have a release bundle, then refer to the most popular answer.
Go to Android Studio > Build > Select Build Variant..
Once you do this your build configuration may start showing errors.
This is because you now need to provide signing details in this configuration as well (this refers signing details from build.gradle)
you may either Edit the configuration and go to the Fix button at the bottom which will ask you to fill in signing details.
Or you may edit the build.gradle
Make sure you provide buildTypes {} and signingConfigs {}
android {
signingConfigs {
release {
storeFile file('<Your PATH>\\keystore.jks')
storePassword 'XXXXX
keyAlias 'XXXXX'
keyPassword 'xxxxx'
}
debug {
storeFile file('<Your PATH>\\keystore.jks')
storePassword 'XXXXX
keyAlias 'XXXXX'
keyPassword 'xxxxx'
}
}
compileSdkVersion 32
defaultConfig {
....
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
}
debug
{
signingConfig signingConfigs.debug
}
}
...
}
dependencies {
...
}
There is one or two minutes of delay before Android Studio starts reflecting correctly. Otherwise, you may do a clean rebuild and then run the app.
When you run the app this time it will be installed in release mode on the target device.
You may need a way to identify the Build Variant of the installed app. You may show the build name and variant somewhere in your app. Or if you have a button somewhere which shows only in debug mode you can check that.
If you have the project you can just build an app with android studio or push it directly to the device if you run a debug or release config with the device connected and selected as the target so long as you enable adb in developer mode on the device and tap trust this computer when you connect it to your machine.
But if you have the bundle because you're trying to install an app pulled from one phone onto another, there are free online services that convert play store links into a direct download of the apk. Just turn on add debugging on the device and adb install <path-to-apk> from the terminal.
If you have more than one device connected with adb enabled you can adb devices to get a list of their identifiers and adb install <path-to-apk> <device-id> will work as well. Or you can use adb to your advantage and do many things on multiple devices at once depending on your needs. There's even ways to adb over wifi.
You will need adb from the android-sdk tools to do any of this though, with Android Studio installed you would have a local installation already but it may not be in your path. However studios terminal likely has access to it since it would be the sdk path your IDE has saved in preferences.. If not you can download a standalone sdk/find out which one studio is using from it's preferences and either
Add adb from the platform-tools directory of said sdk it to your path (best)
Invoke adb from it's absolute path you just located and just keep hitting up to re-use your last command, swapping out the apk/device
cd to the adb directory and just use it with the full path to each of your apks (easiest)
For Windows 11:
PS C:/folder-with-aab-file> java -jar C:\dev\bundletool-all-1.9.1\bundletool.jar build-apks --bundle=app-release.aab --output=app-release.aab.apks --mode=universal
PS C:/folder-with-aab-file> ren app-release.aab.apks app-release.aab.apks.zip
After descompact zip file, the apk file'll with the name: universal.apk
Is there any way to install AABs on devices in the same convenient manner as APKs?
As installing is done by third party apps or mobile company file manager like apps.
The upcoming file managers versions, hence forth, will come with "aab" managing tools.
I searched "android aab installer" on playstore and found one.
deliberately not naming it.
The one I installed, extracted the bundle online,
But after that this app wasn't able to install this extracted app by itself (on my mi [miui] device ).
But this application saved the online extracted apk on phone memory, from where I was able to install it.
remember:
Google's "files" application wasn't able to install this apkbutmy system (in built) filer manager was able to.
Use (on Linux):
cd android
./gradlew assemblyRelease|assemblyDebug
An unsigned APK is generated for each case (for debug or testing)
NOTE: On Windows, replace gradle executable for gradlew.bat
Following is the command and error:
[raj#raj-arch apk]$ adb install android-armv7-release-unsigned.apk
[100%] /data/local/tmp/android-armv7-release-unsigned.apk pkg:
/data/local/tmp/android-armv7-release-unsigned.apk Failure
[INSTALL_PARSE_FAILED_UNEXPECTED_EXCEPTION] rm failed for -f, No such
file or directory
I'm using Ionic and Cordova. Really not sure what's going on with that error though.
try ionic run android or ionic emulate android if on emulator.
Don't mix those.
you can't install unsigned APKs.
Even if it's signed with the debug key, Android only allows a signed APK to be installed.
So you can either follow some of those https://developer.android.com/studio/publish/app-signing.html#signing-manually or How to use jarsigner for signing an apk?
or use the debug version:
adb install android-armv7-debug.apk