我想使用Windows命令行安装一个文件。首先,我想在编译完所有.jar文件后为Android应用程序创建一个.apk文件,而不使用Eclipse。

有人知道如何在不使用Eclipse的情况下,仅通过使用命令行就可以做到这一点吗?


当前回答

按Win+R > cmd 导航到android-sdk windows文件夹中的platform-tools\ 亚洲开发银行类型 现在按照Mohit Kanada所写的步骤(确保你提到了。apk文件的整个路径,例如。d: \ android应用程序\ test.apk)

其他回答

最简单的方法就是通过命令

adb install example.apk

如果你想要目标连接设备你可以添加参数" -d "

adb install -d example.apk

如果你连接了多个设备/模拟器,你会得到这个错误

Adb:错误:连接失败:超过一个设备/模拟器 - waiting for device -错误:超过一个设备/模拟器

为了避免这种情况,您可以通过下面的命令列出所有设备

adb devices

你会得到如下结果

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

选择其中一个设备,并将参数添加到adb命令中,如下所示:“-s a3b09hh3e”

adb -s a3b09a6e install  example.apk

同样作为一个提示,如果apk的路径很长,有一个空格,只需添加它在双引号之间,如

adb -s a3b09a6e install  "c:\my apk location\here 123\example.apk"

您可以通过在关键字'install'之前输入设备/模拟器标识符,然后输入apk的路径,将apk安装到特定的设备/模拟器。注意,'install'关键字后面的-s开关(如果有的话)表示安装到sd卡。例子:

adb -s emulator-5554 install myapp.apk

我在我的windows机器上使用这个脚本(将当前文件夹中的所有apks安装到所有可用设备)

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"

保存为install-apks.ps1

然后是powershell:

powershell -executionpolicy bypass -File .\install-apks.ps1

按Win+R > cmd 导航到android-sdk windows文件夹中的platform-tools\ 亚洲开发银行类型 现在按照Mohit Kanada所写的步骤(确保你提到了。apk文件的整个路径,例如。d: \ android应用程序\ test.apk)

你来这里很可能是因为你也想建造它!

构建

gradlew

(在Windows gradlew.bat上)

然后安装

adb install -r exampleApp.apk

(-r使其替换现有的副本,如果安装在模拟器上,则添加-s)

奖金

我在~/.bash_profile中设置了一个别名

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

(Build and Install的简称)