question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

bundletool fails to generate APKs from AAB

See original GitHub issue

Description

bundletool fails to generate APKs from AAB

Steps to reproduce

  1. Download bundletool and appropriate .aab file (my device is arm64, so I downloaded BraveMonoarm64.aab)
  2. $ alias bundletool='java -jar /home/bruno/Downloads/bundletool-all-1.6.0.jar'
  3. $ bundletool build-apks --bundle=/home/bruno/Downloads/BraveMonoarm64.aab --output=/home/bruno/Downloads/BraveMonoarm64.apks

Actual result

Multiple errors of this sort: “error: failed to deserialize resources.pb: duplicate configuration in resource table.” See below.

$ bundletool build-apks --bundle=/home/bruno/Downloads/BraveMonoarm64.aab --output=/home/bruno/Downloads/BraveMonoarm64.apks
WARNING: The APKs won't be signed and thus not installable unless you also pass a keystore via the flag --ks. See the command help for more information.
/tmp/6272904776128236573/proto.apk: error: failed to deserialize resources.pb: duplicate configuration in resource table.
/tmp/6272904776128236573/proto.apk: error: failed to load APK.
/tmp/2071804396523564826/proto.apk: error: failed to deserialize resources.pb: duplicate configuration in resource table.
/tmp/2071804396523564826/proto.apk: error: failed to load APK.
/tmp/6188646547516233480/proto.apk: error: failed to deserialize resources.pb: duplicate configuration in resource table.
/tmp/6188646547516233480/proto.apk: error: failed to load APK.
/tmp/9019322073981279585/proto.apk: error: failed to deserialize resources.pb: duplicate configuration in resource table.
/tmp/9019322073981279585/proto.apk: error: failed to load APK.
/tmp/6442691279476123884/proto.apk: error: failed to deserialize resources.pb: duplicate configuration in resource table.
/tmp/6442691279476123884/proto.apk: error: failed to load APK.
/tmp/598732138771193428/proto.apk: error: failed to deserialize resources.pb: duplicate configuration in resource table.
/tmp/598732138771193428/proto.apk: error: failed to load APK.
---snip---
/tmp/4148553829505242576/proto.apk: error: failed to deserialize resources.pb: duplicate configuration in resource table.
/tmp/4148553829505242576/proto.apk: error: failed to load APK.
/tmp/5976620259936164327/proto.apk: error: failed to deserialize resources.pb: duplicate configuration in resource table.
/tmp/5976620259936164327/proto.apk: error: failed to load APK.
[BT:1.6.0] Error: Command '[/tmp/AutoValue_BuildApksCommand5394129551921328319/output/linux/aapt2, convert, --output-format, binary, -o, /tmp/5976620259936164327/binary.apk, /tmp/5976620259936164327/proto.apk]' didn't terminate successfully (exit code: 1). Check the logs.
com.android.tools.build.bundletool.model.exceptions.CommandExecutionException: Command '[/tmp/AutoValue_BuildApksCommand5394129551921328319/output/linux/aapt2, convert, --output-format, binary, -o, /tmp/5976620259936164327/binary.apk, /tmp/5976620259936164327/proto.apk]' didn't terminate successfully (exit code: 1). Check the logs.
	at com.android.tools.build.bundletool.model.exceptions.InternalExceptionBuilder.build(InternalExceptionBuilder.java:57)
	at com.android.tools.build.bundletool.androidtools.DefaultCommandExecutor.executeImpl(DefaultCommandExecutor.java:57)
	at com.android.tools.build.bundletool.androidtools.DefaultCommandExecutor.execute(DefaultCommandExecutor.java:33)
	at com.android.tools.build.bundletool.androidtools.Aapt2Command$1.convertApkProtoToBinary(Aapt2Command.java:53)
	at com.android.tools.build.bundletool.io.ApkzlibApkSerializerHelper.writeToZipFile(ApkzlibApkSerializerHelper.java:136)
	at com.android.tools.build.bundletool.io.ApkzlibApkSerializerHelper.writeToZipFile(ApkzlibApkSerializerHelper.java:109)
	at com.android.tools.build.bundletool.io.SplitApkSerializer.writeToDisk(SplitApkSerializer.java:68)
	at com.android.tools.build.bundletool.io.SplitApkSerializer.writeSplitToDisk(SplitApkSerializer.java:42)
	at com.android.tools.build.bundletool.io.ApkSetBuilderFactory$ApkSetArchiveBuilder.addSplitApk(ApkSetBuilderFactory.java:106)
	at com.android.tools.build.bundletool.io.ApkSerializerManager$ApkSerializer.serialize(ApkSerializerManager.java:461)
	at com.android.tools.build.bundletool.io.ApkSerializerManager.lambda$null$3(ApkSerializerManager.java:225)
	at com.google.common.util.concurrent.TrustedListenableFutureTask$TrustedFutureInterruptibleTask.runInterruptibly(TrustedListenableFutureTask.java:125)
	at com.google.common.util.concurrent.InterruptibleTask.run(InterruptibleTask.java:69)
	at com.google.common.util.concurrent.TrustedListenableFutureTask.run(TrustedListenableFutureTask.java:78)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
	at java.lang.Thread.run(Thread.java:748)

Expected result

No errors, APK gets built.

Issue reproduces how often

100% of the time.

Brave version

Release v1.24.84

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
bdantascommented, May 13, 2021

Thank you, wchen342!!! Now it works like a charm 😃

For other users interested in building/installing .apks from the .aab file:

  1. Download appropriate .aab file from Brave’s github page
  2. Make sure you have bundletool and chromium project’s aapt2 (for the latter, see wchen342’s link above)
  3. Create a keystore if you don’t already have one (see https://stackoverflow.com/a/15330139)
  4. Build a self-signed .apks file. My command, as an example, was this:
$ alias bundletool='java -jar /home/bruno/Downloads/bundletool-all-1.6.0.jar'
$ bundletool build-apks --bundle=/home/bruno/Downloads/BraveMonoarm64.aab --output=/home/bruno/Downloads/BraveMonoarm64.apks --aapt2=/home/bruno/Downloads/aapt2 --ks=/home/bruno/Stuff/my-release-key.keystore --ks-pass=pass:passWorD --ks-key-alias=gnuser --key-pass=pass:passWorD
  1. Enable debugging on Android device, connect device to computer, choose “File transfer” on device, on computer: $ adb start-server
  2. Install the .apks to your Android device:
$ bundletool install-apks --apks=/home/bruno/Downloads/BraveMonoarm64.apks

Note that if brave-browser from an official app store is already installed on your Android device, the installation step will fail because when upgrading an app your device requires that current app version and new app version be signed with same signature. Therefore, you have to uninstall the official brave-browser before you can install your self-signed version (I use the oandbackup app to backup my browser’s data so that I can restore the data after installing the self-signed apk).

Happy hacking!

0reactions
bdantascommented, May 13, 2021

P.S. A wishlist item: It would be nice if a link to the appropriate aapt2 binary were provided with each brave-browser release’s “Assets”. This way, “mere mortal” users such as myself would be alerted to the fact that the aapt2 included in buildtool is not going to work. It would also safeguard against problems from users using an outdated aapt2 from chromium source tree.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unable to create an APK from an AAB when system locale is ...
Describe the bug Unable to create a universal APK from an AAB file when ... This is caused by the way bundletool parses...
Read more >
java - Unable to generate APKs from aab using bundletool in ...
INFO: The APKs will be signed with the debug keystore found at 'C:\Users\HP.android\debug.keystore'. [BT:1.11.0] Error: Invalid uncompressed ...
Read more >
bundletool - Android Developers
bundletool is the underlying tool that Android Studio, the Android Gradle plugin, and Google Play use to build an Android App Bundle.
Read more >
Error while publishing AAB to internal sharing console after ...
After this, we always getting error while publishing AAB to the play internal sharing console saying "An error occurred while running bundletool build-apks...
Read more >
How to Generate and Extract APK Files from Android App ...
Using bundletool command, you can extract APK files from Android App Bundle (.aab) and test them manually on different device configurations ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found