Home » Android » Install and Uninstall Android Application ( APK ) using ADB

Install and Uninstall Android Application ( APK ) using ADB

Following shell script does,

  • check if android application is installed
  • find an apk path if android application is already installed.
  • uninstall if its already installed
  • install new apk if application is not installed
#!/bin/bash
ADBPATH=/usr/bin/adb
PACKAGE_NAME=my.app.helloworld
LOCAL_DESKTOP_APK_PATH=$PWD/PACKAGE_NAME.apk

IS_PACKAGE_EXISTS=`$ADBPATH shell pm list packages $PACKAGE_NAME`
echo "pm list package returned: $IS_PACKAGE_EXISTS "
if test -n "$IS_PACKAGE_EXISTS"
then
        echo "Application $PACKAGE_NAME exists"
        CMD=`$ADBPATH shell pm path $PACKAGE_NAME`
        APK_PATH=${CMD:8}
        APK_PATH=$(echo $APK_PATH|tr -d '\n'|tr -d '\r')
        echo "Application is installed at path $APK_PATH"

        echo "uncomment below line if you want to uninstall app"
        echo "$ADBPATH uninstall $PACKAGE_NAME"
        #$ADBPATH uninstall $PACKAGE_NAME
else
        echo "Application $PACKAGE_NAME not found"
        echo "we can install a new apk now"
        $ADBPATH install $LOCAL_DESKTOP_APK_PATH/$PACKAGE_NAME.apk

fi
Manual Install WSA and Android Apps...
Manual Install WSA and Android Apps into Win11

Leave a Comment

Sign up to our newsletter!