bundletool 构建 app bundle

Note:
Do not use the AAPT2 version included in the Android build kit, because it does not support bundletool.
You can find the corresponding version name at this address:
https://maven.google.com/web/index.html#com.android. tools.build:aapt2
replace the name of the download address below (aapt2-3.2.0-alpha18-4804415-windows)
https://dl.google.com/dl/android/maven2/com/android/tools/build/aapt2/ 3.2.0-alpha18-4804415/aapt2-3.2.0-alpha18-4804415-windows.jar

Unzip the Jar package corresponding to the downloaded aapt2, and use the aapt2
aapt2 compile resource
aapt2 compile /Users/guangka123/Documents/test/app_bundle/aapt2/res/image1.png /Users/guangka123/Documents/test/app_bundle/aapt2/ res/image2.png -o compiled_resources

To add the drawable path, otherwise it will not succeed

aapt2 compile /Users/guangka123/Documents/test/app_bundle/aapt2/res/drawable/image1.png -o compiled_resources

Compile the entire directory

aapt2 compile --dir ./oumei/res/ -o omRes.zip

Link to add --proto-format, and then put AndroidManifest, res, resources.pb resources into base.zip

aapt2 link --proto-format -o output.apk -I android.jar --manifest ./AndroidManifest.xml -R ./compiled_resources/*.flat --auto-add-overlay

aapt2 link (res, assets, AndroidManifest.xml resources) out of the apk package

aapt2 link --proto-format -o output.zip -I android.jar -A ./oumei/assets --manifest ./oumei/AndroidManifest.xml -R ./omRes/*.flat --auto-add-overlay

  • Integrate the required resources into base.zip The base.zip structure is as shown in the
    manifest/AndroidManifest.xml module list, in protobuf format.
    dex/... This directory contains one or more compiled DEX files of the application. These files should be named as follows: classes.dex, classes2.dex, classes3.dex, and so on.
    res/... Contains the resources of the module. These resources are in protobuf format and are suitable for all device configurations. The organization of subdirectories and files should be similar to a typical APK.
    root/..., assets/... and lib/... These directories are exactly the same as those described in the section on the Android App Bundle format.
    resources.pb application resource table, in protobuf format

  • Generate aab

    The output path must use an absolute path, otherwise it is invalid

    java -jar bundletool-all-1.4.0.jar build-bundle --modules=base.zip --output=/Users/guangka123/Documents/test/app_bundle/aapt2/myBundle.aab

    The output path must use an absolute path, otherwise it is invalid

    java -jar bundletool-all-1.4.0.jar build-bundle --modules=mybase.zip --output=/Users/guangka123/Documents/test/app_bundle/aapt2/first.aab

Google official document:
https://developer.android.com/studio/build/building-cmdline#build_bundle

Guess you like

Origin blog.51cto.com/xuguohongai/2562991