By Max


2011-08-16 09:38:32 8 Comments

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.

12 comments

@freezing_ 2020-03-16 12:28:17

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

@Mayuri Khinvasara 2019-09-09 07:40:45

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

@live-love 2018-02-19 03:42:22

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

@Graham Borland 2011-08-16 09:40:34

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.

@Dima Kozhevin 2018-07-18 08:28:50

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"

@TSJNachos117 2018-11-02 00:06:40

If you install an app that allows you to connect via ssh as root, this command will work fine. :-)

@Ranjit Virdi 2012-07-20 10:01:51

  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)

@STF 2017-10-30 11:55:47

you need to add it to @Mohit Kanada's answer - and not to write these steps as an answer.

@Hamid 2014-07-26 00:38:08

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!!

@Prashanth Chandra 2016-12-17 08:11:04

You can also add the platform-tools directory to your path, so you don't have to navigate to it every time.

@Gibolt 2017-10-08 08:51:32

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)

@Tarek El-Mallah 2017-02-08 16:04:03

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"

@Mohit Kanada 2011-08-16 10:20:21

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.

@Cow 2014-06-13 21:30:07

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

@Scott Stafford 2015-02-02 16:48:18

adb install -d does NOT force USB. From adb's help: (-d: allow version code downgrade)

@Noyo 2015-08-27 08:52:39

From developer.android.com/tools/help/adb.html#commandsummary : "-d | Direct an adb command to the only attached USB device."

@tanius 2016-03-04 16:26:18

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] while adb install -d file.apk installs the APK with a possible downgrade [see].

@ben_joseph 2017-05-29 07:04:29

Use adb install -r example.apk to install/update an app. The -r will update the app if it's already installed.

@rpattabi 2018-09-17 13:59:39

I was getting INSTALL_FAILED_TEST_ONLY. Adding -t flag solved it.

@Alston 2019-10-02 15:23:17

I can't find the /etc/local/tmp

@Saif 2019-11-13 11:49:23

What if the apk has obb files? How to install then?

@Mohit Kanada 2019-11-14 13:49:41

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.

@Abhisek Mukherjee 2013-04-13 14:12:19

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.

@Darpan 2014-08-04 10:30:04

-s (specific device) = directs the command to device or emulator with serial number specified.

@farid_z 2013-04-02 20:24:26

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

Related Questions

Sponsored Content

19 Answered Questions

[SOLVED] How to install Android SDK Build Tools on the command line?

24 Answered Questions

[SOLVED] Is there a way to get the source code from an APK file?

44 Answered Questions

[SOLVED] Can't start Eclipse - Java was started but returned exit code=13

97 Answered Questions

[SOLVED] "cannot resolve symbol R" in Android Studio

108 Answered Questions

[SOLVED] R cannot be resolved - Android error

34 Answered Questions

[SOLVED] Android Studio: Add jar as library?

8 Answered Questions

[SOLVED] Android error: Failed to install *.apk on device *: timeout

19 Answered Questions

[SOLVED] Build unsigned APK file with Android Studio

33 Answered Questions

[SOLVED] How do you install an APK file in the Android emulator?

23 Answered Questions

[SOLVED] Batch file to delete files older than N days

Sponsored Content