11

Is there an adb command to run on a .apk which gives me the android:versionCode that is set in the AndroidManifest file of that apk?

Basically, how do I get the version code of the apk using adb?

TheWaterProgrammer
  • 7,055
  • 12
  • 70
  • 159

1 Answers1

26

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.

cesar
  • 10,238
  • 2
  • 20
  • 17
Gaurav Bansal
  • 604
  • 5
  • 11
  • 1
    This means that I can do it only after installing the apk on a device? Where is the .apk in this command? – TheWaterProgrammer Jan 31 '19 at 19:03
  • 1
    adb command would only work for installed apk, if you want directly to get this data from apk flle, you should try unzipping it and then try to read AndroidManifest file using File operations. – Gaurav Bansal Jan 31 '19 at 19:11