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.
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
brew install bundletool
. Then just run the commands like this: bundletool build-apks --bundle=./app/release/app.aab --output=./app/release/app.apks
--key-pass=pass:
... is required, but strangely a password is incorrect, so I have to type it manually. After ... install-apks --adb=...
it writes: 'The APKs have been extracted in the directory:...', but that folder doesn't exist, and it doesn't install on device.
C:\Users\Aterr\Desktop\hack>java -jar "C:\Users\Aterr\Desktop\hack\bundletool-all-0.10.3.jar" install-apks --adb="C:\Users\Aterr\AppData\Local\Android\Sdk\platform-tools\adb.exe" --apks="C:\Users\Aterr\Desktop\hack\extractedapks.apks"
For MAC:
brew install bundletool
bundletool build-apks --bundle=./app.aab --output=./app.apks
bundletool install-apks --apks=app.apks
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
https://i.stack.imgur.com/XZonY.png
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.
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 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..
https://i.stack.imgur.com/YIm4E.png
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)
https://i.stack.imgur.com/XQbBZ.png
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.
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.
https://i.stack.imgur.com/lqKbp.png
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
Success story sharing