如何获取 Android AAB 文件的 versionCode 和 versionName(标记)?

Hea*_*ers 9 android android-manifest apk android-app-bundle

类似于获取 Android .apk 文件 VersionName 或 VersionCode 而无需安装 apk,我想获取versionCode和/或versionName仅使用一个.aab文件。

我试过简单地使用经典答案.apk文件,但用我的.aab文件代替,但它没有用:

$ $ANDROID_HOME/sdk/build-tools/29.0.2/aapt dump badging my_aab.aab
ERROR: dump failed because no AndroidManifest.xml found
Run Code Online (Sandbox Code Playgroud)

我也尝试尝试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
Run Code Online (Sandbox Code Playgroud)

Pie*_*rre 14

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

bundletool dump manifest --bundle bundle.aab
Run Code Online (Sandbox Code Playgroud)

并仅提取 versionCode:

bundletool dump manifest --bundle bundle.aab --xpath /manifest/@android:versionCode
Run Code Online (Sandbox Code Playgroud)

希望有帮助。


Hea*_*ers 4

.aabxml文件以协议缓冲区格式存储:

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

并且aapt2有一个convert subcommandthat Converts an apk between binary and proto formats.,它将转换一个.apk仅包含AndroidManifest.xmlproto 格式的文件。因此:

# 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
Run Code Online (Sandbox Code Playgroud)

不幸的是,最终命令没有成功:

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
Run Code Online (Sandbox Code Playgroud)

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

aapt dump xmltree version.apk AndroidManifest.xml
Run Code Online (Sandbox Code Playgroud)