Modify Android App Bundle (aab) Contents before deploying

不打扰是莪最后的温柔 提交于 2020-08-19 10:44:13

问题


We have a build and release pipeline (Azure Devops) that deploys our APK Android app to various appcenter.ms environments. During the release process we unpack the apk, modify the contents with environment specific configuration, and then re-pack the apk.

Now that we are trying to do this with an Android App Bundle (AAB), we can no longer use apktool. How can we achieve the same thing with AAB that we could with APK?

This is a snippet of our working apk version of the script

## NOTE STUFF IS TRUNCATED!!! THIS IS NOT A COMPLETE SCRIPT!!! DO NOT COPY

brew list apktool &>/dev/null || HOMEBREW_NO_AUTO_UPDATE=1 brew install apktool
brew list xmlstarlet &>/dev/null || HOMEBREW_NO_AUTO_UPDATE=1 brew install xmlstarlet

# ... truncated ...

echo "Decompiling $zipPath"
apktool d $zipPath -o "apk"

cd apk

# ... truncated / modify androidmanifest.xml ...

unalignedPath="$apkPath.unaligned"
unsignedPath="$apkPath.unsigned"

cd ..

echo "Repackage apk to $unsignedPath"
apktool b apk -o $unsignedPath

echo "Sign"
jarsigner -keystore $keystorePath -storepass $keystorePass -keypass $keystorePass -verbose -sigalg MD5withRSA -digestalg SHA1 -signedjar $unalignedPath $unsignedPath $keyAlias
jarsigner -verify -verbose -certs $unalignedPath

echo "Zipalign"
$ANDROID_HOME/build-tools/27.0.3/zipalign -f -v 4 $unalignedPath $apkPath

When we simply change the file extension from apk to aab and run the same apktool, our folder structure is kind of messed up.

Also, the resources and manifest are already converted to protobuf, and I don't think I can reverse engineer them.


回答1:


To edit the manifest of the AAB, you'll need to extract the file base/manifest/AndroidManifest.xml from the AAB, e.g.

unzip -p app.aab base/manifest/AndroidManifest.xml > AndroidManifest.pb

At this stage, in spite of its extension, the manifest is in a protocol buffer format (this is why I gave it the extension .pb above). You'll thus then to find a protocol buffer parser/editor to make the changes you need.

To parse the proto, you'll need the definition of the protocol buffer, which you can find in this JAR: https://maven.google.com/com/android/tools/build/aapt2-proto/3.6.3-6040484/aapt2-proto-3.6.3-6040484.jar See message XmlNode in Resources.proto

Once you've made the changes on the parsed proto, re-serialize the proto and re-inject it at the same place with the same name in the AAB (it's just a zip file).

Finally, you don't need to zip-align the AAB, so remove this step.

Maybe in the future a tool will allow do you the conversion for you automatically, similarly to what apktool does. In the meantime, you can do it manually this way. Hope that helps.



来源:https://stackoverflow.com/questions/61462822/modify-android-app-bundle-aab-contents-before-deploying

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!