How to generate an APK (NOT APKS ) from AAB using bundletool? - android

I'm looking for a solution to generate an APK from Android App Bundle which will help me to share the App for internal testing rather publishing on Google Play Beta Testing.
Is there a way or a command using bundletool?

I think that the best option is to use Internal App Sharing that allows to test easily your App Bundles and APKs, including debug builds:
With internal app sharing, you can quickly share an app bundle or APK with your internal team and testers by uploading an APK or app bundle on the internal app sharing upload page.
If you want to go the bundletool route, you need to generate an universal apk. Take a look at this answer on how to do it.

pfmaggi mentioned Internal App Sharing, which is indeed the best way to test exactly what users will get.
An alternative, which isn't as accurate and doesn't always work in some edge cases, is building a universal APK by passing the flag --mode=universal to the build-apks command in bundletool. It still generates an .apks file, but you can then extract the single .apk file from it (using unzip or bundletool's extract-apks command).

You may try this command instead of generating new APK file.
This uses bundletool to install APKS file which generated from bundletool build-apks
bundletool install-apks --apks=file-name.apks

Related

If I sign an AAB with jarsigner, do I need to sign the APKS and also the resulting APKs before deploying?

In Azure DevOps, I'm unzipping an aab, modifying some files (icons, resources, manifest) in the aab, and using bundletool to build the modules. My next steps are:
Use jarsigner to sign the aab
Use bundletool to generate the APKS and passing the signing information
Unzip/extract the universal APK in it
Use jarsigner to sign the APK and send it to test devices
I am assuming that I'm signing more times than necessary since I'm doing it 3 times (the AAB, the APKS, and the APK). Which signing is necessary? It only takes less than 10s for each signing task, but each task adds extra complexity and I would like this as simple as possible for re-usability.
Here's a summary of the required signing:
App Bundle (.aab)
Signing needed (with jarsigner) before uploading to the Play Store.
No signing needed during development or testing.
APK Set (.apks)
Signing not needed. Ever.
APKs (.apk) (the ones inside the APK Set)
Signature always required (unless you're not going to install those APKs).
Bundletool will automatically sign them the APKs it generates in the .apks when pass the --ks flag, so most devs never have to do it themselves.
However, you've mentioned that you modify "some files": if you modify the APKs, you will need to sign them again (ideally with apksigner and not jarsigner -- more secure, and makes APKs faster to install).
This is an example how Generate an Android App Bundle using Xamarin and Azure DevOps: https://damienaicheh.github.io/xamarin/azure/devops/2020/02/03/generate-android-app-bundle-xamarin-azure-devops-en.html
And this documentation about Xamarin.Android app-bundles
https://github.com/xamarin/xamarin-android/blob/master/Documentation/guides/app-bundles.md
Say that: "App Bundles can only be signed with jarsigner (not apksigner). App Bundles do not need to use zipalign. Xamarin.Android should go ahead and sign the .aab file the same as it currently does for .apk files. A com.company.app-Signed.aab file will be generated in $(OutputPath), to match our current behavior with APK files."

How to generate an apk that works without dev server in react native

I'm developing an android application with react-native (0.59), and I want to test it on different devices. My goal is to create an .apk file that can be installed by simply transferring the file, without any requirement for development server running, usb cables, etc..
I have looked at different reply on previous questions about the subject but so far nothing as worked.
This reply still needs a dev-server to run: How to generate dev APK file without asking for dev settings server ip in react native
This reply generate an apk that won't install on the device with the error "app not installed": Build and Install unsigned apk on device without the development server?
I have tried the publish method from the react-native docs (ref: https://facebook.github.io/react-native/docs/signed-apk-android), I generated the .aab file, then I use bundletools to convert it with apks, as explained here: Generate Apk file from aab file (android app bundle) in this answer:
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 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.
But unfortunately in my case, when I open the .zip file, there's no file called universal.apk:
All the .apk are pretty small in size (around 10mb, while the .aab file is 300).
Is there any other solution?
After you go through https://facebook.github.io/react-native/docs/signed-apk-android you can simply run
// for build and run
react-native run-android --variant=release
and take apk in
<rn_project_dir>/android/app/build/outputs/apk/release/app-release.apk

How to install APKs from Google Play Console generated from an Android App Bundle?

I currently upload my app updates on the Google Play Console using the publishing format .aab. My problem is I cannot find a way how to download and install the right APKs generated from .aab.
When I download from the "Manage Releases" like many people suggested, it downloads an .aab. When I download a device specific APK, it gives me three APKs. (In my download case, base.apk, config.en.apk, and config.xxhdpi.apk).
The base APK is able to be installed but cannot launch. The other 2 APKs can't even be parsed. I suspect, these three should be installed as a bundle but I don't know how to do that.
How can I install these three APKs or download the single APK that I can install easily?
You can install these APKs using the adb install-multiple command:
adb install-multiple base.apk config.en.apk config.xxhdpi.apk
Other options you can use:
The internal testing track,
Deploy directly from Android Studio (select "Deploy APK from app bundle" in the Run Configurations.
You can use bundle tool to manipulate the app bundle file and install it on your device locally. First, download bundletool from here. app bundle (the .aab file). Then generate a set of APKs from it by running
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.
Then you can install this APK by running
bundletool install-apks --apks=/MyApp/my_app.apks
The .apks file contains all configurations. If you want to generate a set of APKs for a specific device, take a look at here.

How to generate full APK file including dynamic feature module

My project has dynamic feature module and I would like to generate debug or release APK including the dynamic feature. Currently I can get only base APK file.
Basically I would generate an APK file like normal application. But I couldn't do with dynamic feature. Yes, I know dynamic feature will work based on AAB.
Is there any ways to make a normal(base + all modules) APK file?. Please help on this.
Thanks
I don't see it documented anywhere, but the Android Gradle build tools include tasks to extract the universal APK for you. You can use something similar to:
./gradlew :yourmodule:packageDebugUniversalApk
Under the hood it uses bundletool and does essentially the same thing as the other answer, but it's nice to be able to do it from Gradle.
You can specify if your on demand module needs to be included in the universal APK that is usually generated for older devices, and then you can use bundletool to generate an Universal APK from the App Bundle:.
In this particular case, you can use something like:
bundletool build-apks --bundle <bundle_file> --output <APKS file> --ks <key_store> --key-pass <jks password> --ks-key-alias <key_alias> --ks-pass <key password> --overwrite --mode=universal
The key point is to include the --mode=universal this instruct bundletool to generate an Universal APK that will include all modules that have <dist:fusing dist:include="true"/> in the manifest.
In a similar way, when you run your project from Android Studio on a device, using the default configuration for Run (Deploy = Default APK) it includes all of your on demand modules.
Instead, when you run the application from Studio using the Run configuration (Deploy = APK from AppBundle) you can pick and choose which modules are installed.
However, in both cases, you cannot test on demand module downloads if you don't go through the Play store.
Note (November 2020)
As reported in another answer below, the Android Gradle Plugin includes a couple of undocumented tasks that can be used to generate Debug and unsigned Release universal APKs of your application.
The task related to the Debug version can be a quick alternative if you just need this type of build:
./gradlew :app:packageDebugUniversalApk
This task will generate (by default) app/build/outputs/universal_apk/debug/app-debug-universal.apk.
Update June 2019
Google introduced at I/O Internal App Sharing that allows to allow testing easily your App Bundles and APKs, including debug builds:
With internal app sharing, you can quickly share an app bundle or APK with your internal team and testers by uploading an APK or app bundle on the internal app sharing upload page.
Download bundletool jar file from Github (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
below is the command to generate the universal apk
java -jar bundletool.jar build-apks --bundle=nhl.aab --output=nhl.apks
--mode=universal
`

how to build APK for Android intended for internal distribution?

I'm working on an Android app with React Native.
For testing and developing I just follow the regular dev workflow with a server on my dev machine, reload JS, etc.
Now I want to pass the APK to other people in my company so that they can test the app on their device.
I've been looking into the android folder on my React Native project but I can't find an APK ready to send to other people. It seems the only APK was built when I created the project a few weeks ago, and I'm assuming this APK does not contain any JS code.
I've found these instructions for building a signed app for the Play Store, but I don't need to distribute this APK on the Play Store.
So, how do I create a self contained APK with the JS files and assets that I can easily pass to other people for testing?
From the link you already had in the question, you can skip over the signing details, and just go to "Generating the release APK"
Simply run the following in a terminal:
$ cd android && ./gradlew assembleRelease
Gradle's assembleRelease will bundle all the JavaScript needed to run your app into the APK.
...
The generated APK can be found under android/app/build/outputs/apk/app-release.apk, and is ready to be distributed.

Categories

Resources