This article will tell you how to use ADB ( Android Debug Bridge) to install or uninstall apk file on android devices. You can read the article How To Use Android Debug Bridge (ADB) to learn more if you do not know about android ADB.
1. Use ADB To Install Android Apps Apk File.
1.1 Push app apk file to android device.
//Push to system app folder adb push example.apk /system/app. //Push to user app folder adb push example.apk /data/app.
This method has below disadvantages.
- Maybe overwrite the original app, so you had better use below command to backup the original app before operation.
// Pull android apk from device to local folder. adb pull /system/app/example.apk /user/app_bak
- Usually, you can encounter below error messages.
failed to copy '/user/example.apk' to '/system/app/example.apk': Read-only file system.
This is bacause /system/app folder is read-only, you can not push files into this folder.
To resolve this problem, you need to use adb install command with -r option to force install the apk files, we will introduce it below.
// -r means force install. adb install -r /user/example.apk
Above adb install apk file command will install the apk file into /data/local/tmp/ directory.
1.2 Use adb install command.
- Startup android emulator.
- Run adb install apk file command as below to push android app into emulator /data/app directory.
adb install C:/work/example.apk
- Click the android app icon to run it on the android emulator screen.
2. Use ADB To Uninstall Android Apps Apk File.
2.1 Use ADB Uninstall App Apk File Command.
You can find the android app package name use android device monitor. The package name is located in /data/data folder.
You can refer article Android Device Monitor Cannot Open Data Folder Resolve Method to learn how to use android device monitor.
// Below command will return all the android app packages installed on the connected android device. adb shell pm list packages -f -3 // uninstall android app by app package name. adb uninstall <app package name>
> adb uninstall com.dev2qa.example Success
2.2 Use ADB Shell Command.
> adb shell generic_x86:/ # cd /data/app generic_x86:/data/app # rm com.dev2qa.example.apk
3. Uninstall Android App In Emulator.
You can also use android emulator to uninstall installed android apps.
- Click Settings —> Apps.
- Click the android app that you want to uninstall in app list.
- Click uninstall button in app info panel.
4. How To Uninstall Android Apps Automatically Before Run / Debug Android App In Android Studio.
- Click Run / Debug —> Edit Configurations ( for Windows ) menu item at android studio top menu bar to open the Edit Configurations window.
- If you run android studio on macOS, click Run —> Run / Debug menu item, then it will popup a dialog, click Edit Configurations menu item in the popup dialog to open the Edit Configurations window.
- Select the android app in the popup window left side Android Application section.
- Go to the Before launch area on right-bottom of the popup window, click the
+button then select Run External Tool from the dropdown list.
- Above action will popup another External Tools management dialog, click the
+button at bottom of the popup dialog to add an external tool.
- In the next popup window, input related information to run the external tool. For example, Name : Uninstall App Before Launch, Group : External Tools, Description : It will uninstall android app before launch android app, Program : adb ( or the adb command absolute path if you do not set the path in system environment variable ), Arguments : uninstall app_package_name, etc.
- Click OK button to save above configuration, and check the External Tool ( Uninstall App Before Launch ) in the External Tools list dialog.
- Now the adb uninstall command will be executed every time you start to run the app in android studio.