如何获取安卓 AAB 文件的版本代码和版本名称(徽章)?



类似于在不安装 apk 的情况下获取 Android .apk文件版本名称或版本代码,我想只用一个.aab文件获取versionCode和/或versionName

我尝试简单地对.apk文件使用经典答案,但代替我的.aab文件,但它不起作用:

$ $ANDROID_HOME/sdk/build-tools/29.0.2/aapt dump badging my_aab.aab
ERROR: dump failed because no AndroidManifest.xml found

我还尝试尝试直接转储xmltree

$ $ANDROID_HOME/sdk/build-tools/29.0.2/aapt dump xmltree my_aab.aab base/manifest/AndroidManifest.xml
W/ResourceType(39872): Bad XML block: header size 664 or total size 118110474 is larger than data size 35953
ERROR: Resource base/manifest/AndroidManifest.xml is corrupt

Bundletool 有一个命令来转储 XML 中 AAB 的清单,甚至可以使用 xpath 提取清单的特定属性。

bundletool dump manifest --bundle bundle.aab

并仅提取版本代码:

bundletool dump manifest --bundle bundle.aab --xpath /manifest/@android:versionCode

希望有帮助。

.aab文件以协议缓冲区格式存储其xml

有一个清单文件夹具有Android清单.xml apk中的文件是二进制格式,但在.aab中它是编译成协议缓冲区格式的真实XML文件,因为这可以轻松转换它。

aapt2有一个Converts an apk between binary and proto formats.convertsubcommand,它将转换一个仅包含原型格式AndroidManifest.xml.apk文件。因此:

# Extract the AndroidManifest.xml directly
# without -p, unzip will recreate the directory structure.
unzip -p my_aab.aab base/manifest/AndroidManifest.xml > AndroidManifest.xml
# Create a dummy .apk with the proto-formatted AndroidManifest.xml
zip proto_version.apk AndroidManifest.xml
# Convert the proto-formatted AndroidManifest.xml into an apk-formatted XML
aapt2 convert proto_version.apk -o version.apk
# Now dump the badging
# I don't know why, but dump badging fails, so add `|| true` to make it succeed
aapt dump badging version.apk || true

不幸的是,最后一个命令没有成功:

W/ResourceType(42965): No known package when getting value for resource number 0x7f100000
AndroidManifest.xml:47: error: ERROR getting 'android:icon' attribute: attribute value reference does not exist

但它确实按预期打印versionNameversionCode。您可以使用|| true忽略失败,也可以使用dump xmltree子命令转储原始 XML,这将成功:

aapt dump xmltree version.apk AndroidManifest.xml

最新更新