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

查看:65
本文介绍了部署前修改 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 App Bundle (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 need to find a protocol buffer parser/editor to make the changes you need.

要解析原型,您需要协议缓冲区的定义,您可以在此 JAR 中找到它:https://maven.google.com/com/android/tools/build/aapt2-proto/3.6.3-6040484/aapt2-proto-3.6.3-6040484.jar 查看Resources.proto中的消息XmlNode

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

一旦您对已解析的 proto 进行了更改,请重新序列化该 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-align 对齐,因此请删除此步骤.

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.

简单的分步说明.

  1. 按照上述说明从 AAB 文件中提取 AndroidManifest.xml 文件.对于此用途,请将名称保留为AndroidManifest.xml".
  2. https://developers.google.com/protocol-buffers 下载 protoc 二进制文件/docs/downloads 并将二进制文件解压缩到路径或工作文件夹.
  3. 下载上面引用的 jar 文件,用任意 zip 程序打开 jar,然后复制文件Resources.proto";&Configuration.proto"从 jar 根文件夹到您的工作文件夹.
  4. 运行命令 protoc --decode=aapt.pb.XmlNode Resources.proto AndroidManifest.xml >output.txt 解码文件.
  5. 编辑output.txt"根据您的需要.
  6. 运行 protoc --encode=aapt.pb.XmlNode Resources.proto <输出.txt >AndroidManifest_new.xml 对新版本进行编码.
  1. Extract the AndroidManifest.xml file from the AAB file as instructed above. For this use, keep the name as "AndroidManifest.xml".
  2. Download protoc binary from https://developers.google.com/protocol-buffers/docs/downloads and extract binary to path or working folder.
  3. Download above referenced jar file, open jar with any zip program, and copy the files "Resources.proto" & "Configuration.proto" from the jar root folder to your working folder.
  4. Run command protoc --decode=aapt.pb.XmlNode Resources.proto < AndroidManifest.xml > output.txt to decode the file.
  5. Edit "output.txt" per your needs.
  6. Run protoc --encode=aapt.pb.XmlNode Resources.proto < output.txt > AndroidManifest_new.xml to encode the new version.

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

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