I’ve to install an android app with package name like “com.xyz.game” using adb.
I want to automate the process using shell script. The process will be like if app is already installed, uninstall it(with command adb uninstall com.xyz.game) and install using “adb install game.apk” otherwise simple “adb install game.apk”.
How can I achieve this?
adb shell pm list packages [your.package.name] as mentioned in the below answer
According to (also) correct answer below, try grep the result from pm list packages.
adb shell pm list packages | grep com.your.app.package
If the application is already installed and if you try to install the same app again, adb will return with an error –
Failure [INSTALL_FAILED_ALREADY_EXISTS]. However, if you want to re-install the already installed app, then use
adb install -r game.apk
Try grep the result from pm list packages.
adb shell pm list packages | grep com.xyz.game
You may see the result if already installed.
No need to use grep. Using following commands you can simply check if application is already exist or not.
Run ADB command
adb shell pm list packages [your.package.name]
If app is already installed then above command will return,
Else it won’t return anything i.e. empty String.
Android 7.0 has introduced
cmd (a new native code based) tool which allows to interact with Android services like
PackageManager much faster than the old java bytecode based tools like
pm. So for recent Android versions instead of
adb shell pm list packages <package.name.substring> you should use
adb shell cmd package list packages <package.name.substring>