部署前修改Android App Bundle(aab)内容 [英] Modify Android App Bundle (aab) Contents before deploying

查看:775
本文介绍了部署前修改Android App Bundle(aab)内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个构建和发布管道(Azure Devops),可将我们的APK Android应用程序部署到各种appcenter.ms环境中.在发布过程中,我们将apk打包,使用特定于环境的配置修改内容,然后重新打包apk.

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.

现在,我们正在尝试使用Android应用程序捆绑包(AAB)进行此操作,因此我们将无法再使用apktool.怎样用AAB实现与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?

这是我们脚本的工作 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

当我们简单地将文件扩展名从apk更改为aab并运行相同的apktool时,我们的文件夹结构有点混乱.

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

此外,资源和清单已经转换为protobuf,我认为我不能对其进行反向工程.

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

推荐答案

要编辑AAB的清单,您需要从AAB中提取文件base/manifest/AndroidManifest.xml,例如

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

在此阶段,清单尽管有扩展名,但仍采用协议缓冲区格式(这就是为什么我在上面给它扩展名.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.

要解析原型,您需要协议缓冲区的定义,您可以在此JAR中找到它:

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

对解析后的原型进行更改后,请重新序列化该原型,然后将其重新注入到AAB中相同名称的同一位置(这只是一个zip文件).

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).

最后,您无需对AAB进行zip对齐,因此请删除此步骤.

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

也许将来某个工具会自动允许您进行转换,类似于apktool所做的那样.同时,您可以通过这种方式手动进行操作.希望有帮助.

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.

这篇关于部署前修改Android App Bundle(aab)内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆