Android 使用 adb 获取应用程序版本名称
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11942762/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Get application version name using adb
提问by frognosis
Is there an easy way to get the version name of an application on an Android device using adb shell?
有没有一种简单的方法可以使用 adb shell 在 Android 设备上获取应用程序的版本名称?
I found the application version number (not the version name) in /data/system/packages.xml.
我在 /data/system/packages.xml 中找到了应用程序版本号(不是版本名称)。
It would be nice if there was a file that contained the Application Info.
如果有一个包含应用程序信息的文件就好了。
回答by arbuz
adb shell dumpsys package my.package | grep versionName
as mentioned by @davidand @Jeremy Fishman. This will be much quicker than:
正如@david和@Jeremy Fishman所提到的。这将比:
adb shell dumpsys | grep -A18 "Package \[my.package\]"
回答by MonoThreaded
Dumpsys package is your friend
Dumpsys 软件包是您的朋友
~/# adb shell
shell@mo:/ dumpsys package tld.comp.app_name | grep version
Will return
将返回
versionCode=X targetSdk=YY
versionName=Z.Z
回答by LLL
In case someone needs all apps versions for comparing purposes then here is my oneliner:
如果有人需要所有应用程序版本进行比较,那么这里是我的 oneliner:
for p in `adb shell pm list package | awk -F"package:" '{print }'`; do echo -n "$p: "; adb shell dumpsys package $p | grep -i versionName | awk -F"=" '{print }'; done
Maybe it will be helpful for somebody but please note that I use versionName and ignore versionCode, so use with care.
也许这对某些人会有所帮助,但请注意,我使用 versionName 并忽略 versionCode,因此请谨慎使用。
回答by user541686
If you want to get all package versions, try this awk script:
如果你想获得所有的包版本,试试这个 awk 脚本:
adb shell dumpsys package | awk '/^[ ]*Package \[.*\] (.*)/ { i = index($ANDROID_HOME/build-tools/28.0.3/aapt dump badging app/build/outputs/apk/app.app
, "[") + 1; pkg = substr(##代码##, i, index(##代码##, "]") - i); } /[ ]*versionName=/ { { print pkg "\t" substr(##代码##, index(##代码##, "=") + 1); pkg = ""; } }'
回答by SergeyUr
If you don't want install *.apk on device but you need get version of app, you can do it as follow
如果您不想在设备上安装 *.apk 但您需要获取应用程序版本,您可以按照以下步骤进行
##代码##