【问题标题】:How do I get the versionCode and versionName (badging) of an Android AAB file?如何获取 Android AAB 文件的 versionCode 和 versionName(标记)?
【发布时间】:2020-02-10 17:59:33
【问题描述】:

类似于Get Android .apk file VersionName or VersionCode WITHOUT installing apk,我想通过.aab 文件获取versionCode 和/或versionName

我尝试过简单地使用the classic answer for .apk files,但用我的.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

【问题讨论】:

    标签: android apk android-manifest android-app-bundle


    【解决方案1】:

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

    bundletool dump manifest --bundle bundle.aab
    

    只提取版本代码:

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

    希望对您有所帮助。

    【讨论】:

    • 谢谢。这很有帮助,但我试图找到一种仅使用 vanilla Android SDK 显示它的方法,而 bundletool 不在 vanilla Android SDK 中。
    【解决方案2】:

    .aab 文件将其xml 存储在protocol buffer format 中:

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

    aapt2 有一个convert subcommand 那个Converts an apk between binary and proto formats.,它会转换一个.apk 文件,其中只包含一个原始格式的AndroidManifest.xml。因此:

    # 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
    

    【讨论】:

      猜你喜欢
      • 2017-12-21
      • 1970-01-01
      • 1970-01-01
      • 2012-03-26
      • 2012-11-08
      • 1970-01-01
      • 2017-10-12
      • 1970-01-01
      • 2018-04-30
      相关资源
      最近更新 更多