Get Android .Apk File Versionname or Versioncode Without Installing APK

Adb command to get versionCode from apk

For Version Name :

adb shell dumpsys package my.package | grep versionName

For Version Code :

adb shell dumpsys package my.package | grep versionCode

Also you can try this below too:

Android: Get versionName or versionCode of an APK from the command line
You can use aapt in android's build-tools directory of whatever build tools version you're using.

You pass that tool the badging command, and then pass it the location of your APK.

Example:

$ANDROID_HOME/build-tools/24.0.2/aapt dump badging app/build/outputs/apk/app-release.apk

If you scroll through all the output, you can find the versionName and versionCode.

APK with same versionName but different versionCode

The versionName is just something displayed to the user, from Google and Android perspective this field is simply ignored. The only relevant field is versionCode.

Therefore yes, users will get that update if only versionCode has changed.

Find versionnumber and versioncode of apk generated by android studio

Just use AAPT from your path/to/your/android-sdk/build-tools/your-api-version-available/...

An example of the command execution:

aapt dump badging theuserapp.apk

And it will respond with something like:

package: name='com.blabla.theuserapp' versionCode='2000' versionName='2.0.0'

Of course, as the tool is an executable which produces a raw text output you can easily script it and parse from your favorite scripting languaje.

How do I get the versionCode and versionName (badging) of an Android AAB file?

.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


Related Topics



Leave a reply



Submit