653

I want to install a file using the Windows command line. First I want to build after compiling all the .jar files to create an .apk file for an Android application without using Eclipse.

Does anyone know how this can be done without the use of Eclipse & only by making use of command line.

wonea
  • 4,783
  • 17
  • 86
  • 139
Max
  • 7,003
  • 4
  • 19
  • 17
  • http://stackoverflow.com/questions/3480201/how-do-you-install-an-apk-file-in-the-android-emulator Right Way to Install Apk in emulater – Naveen Tamrakar Aug 12 '13 at 07:23
  • 2
    http://android.stackexchange.com/questions/12961/command-to-install-app-from-phone – Ciro Santilli OurBigBook.com Dec 04 '15 at 19:22
  • I voted to close this because (a) it's on topic on [android.se], (b) it's answered there better, (c) it's basically "how do I install something" which is about as basic as it gets. https://android.stackexchange.com/questions/169384/how-to-install-app-from-command-line-terminal – Evan Carroll Jul 18 '22 at 00:54

14 Answers14

989

You can use the code below to install application from command line

adb install example.apk

this apk is installed in the internal memory of current opened emulator.

adb install -s example.apk

this apk is installed in the sd-card of current opened emulator.

You can also install an apk to specific device in connected device list to the adb.

adb -s emulator-5554 install myapp.apk

Refer also to adb help for other options.

Ready Android
  • 3,529
  • 2
  • 26
  • 40
Mohit Kanada
  • 15,274
  • 8
  • 31
  • 41
  • 17
    Just to add to this for anyone having issues in the future, add `-d` to force the installation over USB connections. I had issues, and adding that fixed it. `adb -d install myApp-release.apk` – Cow Jun 13 '14 at 21:30
  • 9
    `adb install -d` does NOT force USB. From adb's help: `(-d: allow version code downgrade)` – Scott Stafford Feb 02 '15 at 16:48
  • 6
    From http://developer.android.com/tools/help/adb.html#commandsummary : "-d | Direct an adb command to the only attached USB device." – Noyo Aug 27 '15 at 08:52
  • 60
    The answer to the `-d` confusion is, both @ZachCase and @ScottStafford are correct. ADB options and ADB command options are different things: `adb -d install file.apk` installs to the single Android device connected by USB [[see](http://developer.android.com/tools/help/adb.html#commandsummary)] while `adb install -d file.apk` installs the APK with a possible downgrade [[see](http://developer.android.com/tools/help/shell.html#pm)]. – tanius Mar 04 '16 at 16:26
  • 20
    Use `adb install -r example.apk` to install/update an app. The `-r` will update the app if it's already installed. – ben_joseph May 29 '17 at 07:04
  • I was getting `INSTALL_FAILED_TEST_ONLY`. Adding `-t` flag solved it. – rpattabi Sep 17 '18 at 13:59
  • I can't find the `/etc/local/tmp` – Alston Oct 02 '19 at 15:23
  • What if the apk has obb files? How to install then? –  Nov 13 '19 at 11:49
  • Install APK first. Once app installed don't run it. Just unzip your obb file and put it under application folder created. Once obb file is placed you can start application. – Mohit Kanada Nov 14 '19 at 13:49
  • I had to pull it onto my laptop first: `adb pull "/storage/self/primary/Download/app.apk" ~/Downloads/app.apk` – oliversisson Feb 19 '21 at 06:14
  • `adb: failed to install app-release.apk: Failure [INSTALL_FAILED_UPDATE_INCOMPATIBLE: Package com.yourApp signatures do not match previously installed version; ignoring!]` If you're getting this error you can use this command to uninstall the app. `adb uninstall "com.yourApp"` – Thevin Malaka. Sep 27 '22 at 11:02
81

You can build on the command line with ant. See this guide.

Then, you can install it by using adb on the command line.

adb install -r MyApp.apk

The -r flag is to replace the existing application.

Deming
  • 1,210
  • 12
  • 15
Graham Borland
  • 60,055
  • 21
  • 138
  • 179
48

Use the Android Debug Bridge command line tool adb eg: adb install filename.apk.

A good reference for adb is Here

install [options] <PATH>    Installs a package (specified by <PATH>) to the system.
Options:

-l: Install the package with forward lock.
-r: Reinstall an exisiting app, keeping its data.
-t: Allow test APKs to be installed.
-i <INSTALLER_PACKAGE_NAME>: Specify the installer package name.
-s: Install package on the shared mass storage (such as sdcard).
-f: Install package on the internal system memory.
-d: Allow version code downgrade.
uninstall [options] <PACKAGE>   Removes a package from the system.
Options:

-k: Keep the data and cache directories around after package removal.
George
  • 2,860
  • 18
  • 31
  • 2
    -s (specific device) = directs the command to device or emulator with serial number specified. – Darpan Aug 04 '14 at 10:30
42

You can install an apk to a specific device/emulator by entering the device/emulator identifier before the keyword 'install' and then the path to the apk. Note that the -s switch, if any, after the 'install' keyword signifies installing to the sd card. Example:

adb -s emulator-5554 install myapp.apk
farid_z
  • 1,673
  • 21
  • 11
37

The simple way to do that is by command

adb install example.apk

and if you want to target connect device you can add parameter " -d "

adb install -d example.apk

if you have more than one device/emulator connected you will get this error

adb: error: connect failed: more than one device/emulator - waiting for device - error: more than one device/emulator

to avoid that you can list all devices by below command

adb devices

you will get results like below

 C:\Windows\System32>adb devices 
 List of devices attached 
 a3b09hh3e    device 
 emulator-5334    device

chose one of these devices and add parameter to adb command as " -s a3b09hh3e " as below

adb -s a3b09a6e install  example.apk

also as a hint if the path of the apk long and have a spaces, just add it between double quotes like

adb -s a3b09a6e install  "c:\my apk location\here 123\example.apk"
Tarek El-Mallah
  • 4,015
  • 1
  • 31
  • 46
27

Commands for install APK files like it does in Android Studio you can see below.

1) To push your app:

adb push /pathOfApk/com.my.awesome.apk /data/local/tmp/com.my.awesome

where com.my.awesome is your package.

2) To install:

adb shell pm install -t -r "/data/local/tmp/com.my.awesome"
Dima Kozhevin
  • 3,602
  • 9
  • 39
  • 52
23

Open Terminal in Android Studio

You might see

C:\Users\nikhil\AppData\Local\Android\Sdk\platform-tools>

copy and paste your apk which you want to install on above path inside platform-tools. In my case app-qa-debug.apk I kept inside platform-tools folder.

install command

adb install app-qa-debug.apk

so in the terminal you could see something

C:\Users\nikhil\AppData\Local\Android\Sdk\platform-tools>adb install app-qa-debug.apk

post-installation you could get the message as

Performing Streamed

Install Success

Nikhil Lotke
  • 605
  • 7
  • 15
19
  1. Press Win+R > cmd
  2. Navigate to platform-tools\ in the android-sdk windows folder
  3. Type adb
  4. now follow the steps writte by Mohit Kanada (ensure that you mention the entire path of the .apk file for eg. d:\android-apps\test.apk)
wonea
  • 4,783
  • 17
  • 86
  • 139
Ranjit Virdi
  • 207
  • 2
  • 2
  • 1
    you need to add it to @Mohit Kanada's answer - and not to write these steps as an answer. – STF Oct 30 '17 at 11:55
12

It is so easy!

for example my apk file location is: d:\myapp.apk

  1. run cmd

  2. navigate to "platform-tools" folder(in the sdk folder)

  3. start your emulator device(let's say its name is 5556:MyDevice)

  4. type this code in the cmd:

    adb -s emulator-5556 install d:\myapp.apk

Wait for a while and it's DONE!!

wonea
  • 4,783
  • 17
  • 86
  • 139
Hamid
  • 139
  • 1
  • 5
5

You're likely here because you want to build it too!

Build

gradlew

(On Windows gradlew.bat)

Then Install

adb install -r exampleApp.apk

(The -r makes it replace the existing copy, add an -s if installing on an emulator)

Bonus

I set up an alias in my ~/.bash_profile

alias bi="gradlew && adb install -r exampleApp.apk"

(Short for Build and Install)

Community
  • 1
  • 1
Gibolt
  • 42,564
  • 15
  • 187
  • 127
5

To install a debug (test) apk, use -t:

Run Build-Make Project

Look for the last generated apk in the app folder.

Example:

adb  install -t C:\code\BackupRestore\app\build\outputs\apk\debug\app-debug.apk
live-love
  • 48,840
  • 22
  • 240
  • 204
4

You can do this by using adb command line tools OR gradle commands: See this Guide.

Setup command line adb

export PATH=/Users/mayurik/Library/Android/sdk/platform-tools/adb:/Users/mayurik/Library/Android/sdk/tool

Gradle commands to build and install.

 #Start Build Process
    echo "\n\n\nStarting"
    ./gradlew clean

    ./gradlew build

    ./gradlew assembleDebug

    #Install APK on device / emulator
    echo "installDebug...\n"

    ./gradlew installDebug

You can also uninstall any previous versions using

  `./gradlew uninstallDebug`

You can launch your main activity on device/emulator like below

#Launch Main Activity
adb shell am start -n "com.sample.androidbuildautomationsample/com.sample.androidbuildautomationsample.MainActivity" -a android.intent.action.MAIN -c android.intent.category.LAUNCHER
Mayuri Khinvasara
  • 1,437
  • 1
  • 16
  • 12
3

I use this script on my windows machine ( insall all apks in current folder to all available devices )

Write-Host "Listing APKs..."

$List_Apks = New-Object System.Collections.ArrayList

Get-ChildItem -Path .\ -Filter *.apk -File -Name| ForEach-Object {
    $apk_filename = [System.IO.Path]::GetFileName($_)
    $List_Apks+=$apk_filename
    $apk_filename
}

Write-Host "Found apks "$List_Apks.Length
Write-Host ""

$raw_list = adb devices
$array_lines = $raw_list.Split("\n")

Write-Host "Listing devices "

$List_Device_Ids = New-Object System.Collections.ArrayList

1..($array_lines.Length-2) | foreach {
  $device_id = $array_lines[$_].Split([char]0x9)[0]
  $List_Device_Ids+=$device_id
  $device_id
}

Write-Host "Found devices "$List_Device_Ids.Length

0..($List_Device_Ids.Length-1) | foreach {
    $device_id = $List_Device_Ids[$_]

    0..($List_Apks.Length-1) | foreach {
        $apk_file_name = $List_Apks[$_]

        Write-Host "Installing " $apk_file_name "->" $device_id

        adb -s $device_id install -r $apk_file_name
    }
}


Write-Host "Endo"

Save this as install-apks.ps1

Then from the powershell :

powershell -executionpolicy bypass -File .\install-apks.ps1
freezing_
  • 984
  • 1
  • 9
  • 13
2

For people who wants to load apk from Linux system with React native application running on it. I have given the path in which the android application resides as well. So that those who need to find the apk file can go to view it.

adb -s 434eeads install android/app/build/outputs/apk/debug/app-debug.apk

For reinstalling the android app on phone

adb -s 434eeads install -r android/app/build/outputs/apk/debug/app-debug.apk

-s -> source/serialNumber

r -> Re-install path + file name : android/app/build/outputs/apk/debug/app-debug.apk

It is for react native applications.

Uncle Sam
  • 33
  • 3
Sunil Kumar
  • 388
  • 5
  • 15