How to rebuild the .aab file after some resources changes from exiting .aab

1.9k Views Asked by At

I've generated the .aab file using the ./gradlew bundle command. Latter unzipped the .aab got resources and dex files. Now I want to change some version code in AndroidManifest.xml, some resource files, and again need to recompile the same .aab file.

In the case of .apk, we can achieve using APKTool(reverse engineering) this working perfectly.

Since we have to move from APK to AAB, I'm unable to rebuild after modification .aab file. Please give your pointers on how to do this using the commands?.

Thanks in advance!!

2

There are 2 best solutions below

4
Ben Weiss On

Generally we recommend not to manipulate the .aab file manually but let bundletool do the task.

The recommendation is to use ./gradlew bundle as you have done in the first instance, after applying changes to the project that is being built. The resulting .aab file will contain these changes.
This means you won't have to manipulate the contents by hand.

1
htafoya On

You can use bundletool to do so if you only need to change assets, I have not yet tested if you can alter sources as with APK+apktool.

BundleTool:

Alter AAB files:

  1. Extract the BUILD.aab to the same directory where bundletool.jar is.

  2. Open terminal and execute the following command to extract the aab zip.

    unzip BUILD.aab -d ./aab_unpack

  3. Once finished, search directory for the files you want to edit. As a recommendation use terminal or an script editor to avoid creating .DS_STORE files.

  4. In case you need it, move to root of aab_unpack and delete the .DS_STORE files with the next command: find . -name ".DS_Store" -delete

  5. Move to aab_unpack/base folder and create a base.zip under the same directory where bundletool.jar is. Use the next command:

    zip -r --no-dir-entries ../../base.zip *

  6. Repack using bundletool.jar

    java -jar bundletool.jar build-bundle --modules base.zip --output BUILD_REPACK.aab

  7. Verify the aab file generated with the next command

    java -jar bundletool.jar validate --bundle BUILD_REPACK.aab

You should get a message like this:

enter image description here

  1. Sign the abb file with jarsigner

    /Library/Java/JavaVirtualMachines/jdk-11.0.4.jdk/Contents/Home/bin/jarsigner -verbose -sigalg SHA1withRSA -digestalg SHA1 -keystore YOUR_KEY.jks -signedjar BUILD_OUTPUT_SIGNED.aab BUILD_REPACK.aab ALIAS_NAME