20

Similar to Get Android .apk file VersionName or VersionCode WITHOUT installing apk, I want to get the versionCode and/or versionName with just an .aab file.

I've tried simply using the classic answer for .apk files, but substituting my .aab file instead, and it didn't work:

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

I also tried attempting to dump the xmltree directly:

$ $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 

I'd like to do this with the plain Android SDK, and not install any external tools.

3 Answers 3

39

Bundletool has a command to dump the manifest of the AAB in XML, and even extract specific attributes of the manifest using xpath.

bundletool dump manifest --bundle bundle.aab 

And to extract just the versionCode:

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

Hope that helps.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks. This is helpful, but I was trying to find a way to show it with just the vanilla Android SDK, and bundletool isn't in the vanilla Android SDK.
bundletool is mentionned in Android doc : developer.android.com/studio/command-line/bundletool
5

.aab files store their xml in a protocol buffer format:

There is manifest folder having Android Manifest.xml file in the apk it is in binary format but in .aab it is real XML file compiled into a protocol buffer format because this allows to transform it easily.

And aapt2 has a convert subcommand that Converts an apk between binary and proto formats., and it will convert a .apk file that contains only an AndroidManifest.xml in proto format. Thus:

# 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 

Unfortunately, the final command doesn't succeed:

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 

But it does print the versionName and versionCode as expected. You can ignore the failure with || true, or you can use the dump xmltree subcommand to dump the raw XML, which succeeds:

aapt dump xmltree version.apk AndroidManifest.xml 

Comments

3
# 1. Download bundletool.jar wget --output-document=bundletool.jar \ https://github.com/google/bundletool/releases/download/1.15.6/bundletool-all-1.15.6.jar # 2. Run Jar with <name>.aab file like argument. java -jar bundletool.jar dump manifest --bundle app.aab --xpath /manifest/@android:versionCode java -jar bundletool.jar dump manifest --bundle app.aab --xpath /manifest/@android:versionName 

1 Comment

There is a comment above that talks about bundletool

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.