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

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


当前回答

我在我的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

其他回答

您可以使用ant在命令行上进行构建。请看这个指南。

然后,您可以在命令行上使用adb安装它。

adb install -r MyApp.apk

-r标志将替换现有的应用程序。

要安装调试(测试)apk,使用-t:

运行Build-Make项目

在app文件夹中查找最后生成的apk。

例子:

adb  install -t C:\code\BackupRestore\app\build\outputs\apk\debug\app-debug.apk

对于想要从Linux系统加载apk并在其上运行React本机应用程序的人。 我已经给出了路径,其中android应用程序驻留以及。这样需要查找apk文件的人就可以去查看了。

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

用于重新安装手机上的android应用程序

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

s ->源代码/副号码

r ->重新安装 路径+文件名:android/app/build/outputs/apk/debug/app-debug.apk

它适用于react原生应用程序。

我在我的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

命令安装APK文件,就像它在Android工作室,你可以看到下面。

1)推广应用:

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

com.my.awesome是你的包裹。

2)安装:

adb shell pm install -t -r "/data/local/tmp/com.my.awesome"