简体   繁体   English

如何将多个 android 应用程序(从 apk 文件)安装到设备中?

[英]How to install multiple android applications ( from apk files) into device?

I have 50 apk files and I need to install it to many android devices.我有 50 个 apk 文件,我需要将它安装到许多 Android 设备上。 How can I install it with one click.如何一键安装。 I can install an apk file using adb via "install" command but how to install 50 apk files at once?我可以通过“安装”命令使用 adb 安装 apk 文件,但如何一次安装 50 个 apk 文件?

I'm using Windows我正在使用 Windows

Thanks.谢谢。

在 Windows 中,您可以使用以下命令行:

for %f in (C:\your_app_path\*.apk) do adb install "%f"

you can either use (from ADB help):您可以使用(来自ADB帮助):

adb install-multiple [-lrtsdpg] <file...>
                             - push this package file to the device and install it
                               (-l: forward lock application)
                               (-r: replace existing application)
                               (-t: allow test packages)
                               (-s: install application on sdcard)
                               (-d: allow version code downgrade)
                               (-p: partial application install)
                               (-g: grant all runtime permissions)

which is prefered over installing one-by-one, since you'll be saving some overhead connection-time over each command connecting/disconnecting to your device's modem,这比逐个安装更可取,因为您将在每个连接/断开设备调制解调器的命令上节省一些开销连接时间,

generally speaking, use the install-multiple while escaping the package name (your apk files), you better make sure the apk files-names do not have spaces or you'll have to escape the file-names.一般来说,在转义包名称(您的 apk 文件)时使用install-multiple ,最好确保 apk 文件名没有空格,否则您必须转义文件名。 if you are using windows's cmd escaping and wrapping with " is mandatory, unless you are using a little trick: dropping a few apk files over a batch file and using the %* as argument.如果您使用的是 Windows 的 cmd 转义和包装,则"是强制性的,除非您使用了一个小技巧:将一些 apk 文件放在批处理文件上并使用%*作为参数。

if you are still on the "I want to install one-by-one, use my script from the following answer https://stackoverflow.com/a/34553043/257319 it will allow you an unlimited amount of arguments, while properly shortening the apk-file name in the install command..如果您仍然处于“我想逐个安装,请使用以下答案https://stackoverflow.com/a/34553043/257319中的我的脚本,它将允许您无限量的参数,同时正确缩短安装命令中的 apk 文件名..

another alternative is batch compressing the whole APK to a 'storage-compression zip' pushing it to the sdCard, uncompressing it to a tmp folder, and using shell to install the packages one by one, but since those exist locally the overhead of "adb-to-modem conversations" would be almost none :)另一种选择是将整个 APK 批量压缩为“存储压缩 zip”,将其推送到 sdCard,将其解压缩到 tmp 文件夹,并使用 shell 一个一个地安装包,但由于这些包存在于本地,因此“adb”的开销-to-modem 对话”几乎没有 :)

happy installation :]安装愉快:]

Are you using linux ?你用的是linux吗? You could copy all apks to one directory, and then run simply use:您可以将所有 apk 复制到一个目录,然后简单地运行:

#!/bin/sh
for file in /dir/*
do
  adb install $file 
done

This worked for me:这对我有用:

ls *.apk | cut -d' ' -f9 | tr '\r' ' ' | xargs -r -n1 -t adb install

All the APKs were present in the current directory.所有 APK 都存在于当前目录中。 (performed on Ubuntu) (在 Ubuntu 上执行)

I found the solution.我找到了解决方案。 Its actually very simple:它实际上非常简单:

adb install application1.apk & adb install application2.apk & adb install applicaiton3 adb install application1.apk & adb install application2.apk & adb install applicaiton3

That's what i was looking for.这就是我一直在寻找的。 Thanks everyone感谢大家

Based (and thanks) on the answer by alextooter and edited by Manoj Khanna基于(并感谢)alextooter 的回答并由 Manoj Khanna 编辑

I came up with this:我想出了这个:

In Windows, you can using this command line:在 Windows 中,您可以使用以下命令行:

for %f in (C:\your_app_path\*.apk) do adb install "%f"

In a batch file:在批处理文件中:

you can use %%f and "%%f" instead, and after truly long hours working on this, I came up with this pretty neat solution on a batch file:您可以使用 %%f 和 "%%f" 代替,经过长时间的工作后,我在批处理文件中提出了这个非常简洁的解决方案:

@echo Preparing to install all .apk files in "C:\My Hardware\Cell Phone\APKs\" folder to device

@pause

@for /f "delims=|" %%f in ('dir /b "C:\My Hardware\Cell Phone\APKs\"*.apk') do @"C:\My Hardware\Cell Phone\ADB\adb.exe" install -r "C:\My Hardware\Cell Phone\APKs\%%f"

@echo End of Batch File

@pause

This batch file gave this output, [notice a couple of errors, because unconventional characters in the file name (™ trade Mark Char and the '&' symbol), but nothing to worry about, that'll be another topic.]这个批处理文件给出了这个输出,[注意几个错误,因为文件名中有非常规字符(™ 商标字符和“&”符号),但没什么好担心的,这将是另一个话题。]

[One final remark. [最后一句话。 The original folder address was a lot longer that just 'my hardware' and it was edited for illustrative purposes only, if by any chance it was forgotten to edit in some other line(s) then be aware.原始文件夹地址比“我的硬件”要长得多,并且仅出于说明目的进行了编辑,如果有任何机会忘记在其他行中进行编辑,请注意。 It was triple checked, but anyways, one never knows.]它经过三重检查,但无论如何,人们永远不会知道。]

so, on with the Screen Output Copy-Paste:因此,使用屏幕输出复制粘贴:

Preparing to install all .apk files in "C:\My Hardware\Cell Phone\APKs\" folder to device

Press any key to continue . . .

2119 KB/s (3730200 bytes in 1.718s)

        pkg: /data/local/tmp/AdAway_v3 (04-2015).apk

Success

2349 KB/s (39102487 bytes in 16.250s)

        pkg: /data/local/tmp/Amazon Kindle_4.13.0.203_1144258763.apk

Success

1681 KB/s (591738 bytes in 0.343s)

        pkg: /data/local/tmp/Apk Extractor_3.04.apk

Success

1824 KB/s (2685472 bytes in 1.437s)

        pkg: /data/local/tmp/CCleaner_v1.11.43_71411143.apk

Success

1433 KB/s (22935 bytes in 0.015s)

        pkg: /data/local/tmp/Contenidos_1.0_1.apk

Success

can't find 'C:\My Hardware\Cell Phone\APKs\Digital clock XperiaT_3.8.0.96_96.apk' to install

2955 KB/s (189128 bytes in 0.062s)

        pkg: /data/local/tmp/DiskUsage_3.5.3_3053.apk

Success

1761 KB/s (873714 bytes in 0.484s)

        pkg: /data/local/tmp/Galactic Core Free_2.41_43.apk

Success

2619 KB/s (11988685 bytes in 4.468s)

        pkg: /data/local/tmp/Gmail_5.3.95312851_53000576.apk

Success

2380 KB/s (2856307 bytes in 1.171s)

        pkg: /data/local/tmp/Goggles_1.9.4_211.apk

Success

2555 KB/s (38071805 bytes in 14.546s)

        pkg: /data/local/tmp/Google App_4.7.13.19.arm_300412076.apk

Success

2467 KB/s (23850128 bytes in 9.437s)

        pkg: /data/local/tmp/Google Keyboard_4.1.22063.1974169_22063.apk

Success

2682 KB/s (9999424 bytes in 3.640s)

        pkg: /data/local/tmp/Google Play Books_3.4.9_30409.apk

Success

2141 KB/s (13604976 bytes in 6.203s)

        pkg: /data/local/tmp/Google Play Games_3.1.11 (2044178-030)_31110030.apk

Success

2689 KB/s (9640324 bytes in 3.500s)

/system/bin/sh:  TV_3.8.8_38081.apk: not found

/system/bin/sh:  TV_3.8.8_38081.apk: not found

2761 KB/s (17101587 bytes in 6.046s)

        pkg: /data/local/tmp/Google Play Music_6.0.1945S.2039625_1945.apk

Success

2694 KB/s (7631202 bytes in 2.765s)

        pkg: /data/local/tmp/Google Play Newsstand_3.2.0_2014040406.apk

Success

2371 KB/s (41779806 bytes in 17.203s)

        pkg: /data/local/tmp/Google Play services_7.5.74 (1997312-030)_7574030.apk

Success

2759 KB/s (13424078 bytes in 4.750s)

        pkg: /data/local/tmp/Google Text-to-speech Engine_3.4.6.1819666.arm_2103
04060.apk

Success

2448 KB/s (34089466 bytes in 13.593s)

        pkg: /data/local/tmp/Google+_5.8.0.96635860_414049433.apk

Success

2499 KB/s (20197317 bytes in 7.890s)

        pkg: /data/local/tmp/Hangouts_3.3.94322993_22401362.apk

Success

2371 KB/s (13280248 bytes in 5.468s)

        pkg: /data/local/tmp/Keep_3.1.204.00_3120400.apk

Success

2672 KB/s (20566942 bytes in 7.515s)

        pkg: /data/local/tmp/Maps_9.10.1_910100121.apk

Success

2292 KB/s (5759074 bytes in 2.453s)

        pkg: /data/local/tmp/Nova Launcher_4.0.1_40100.apk

Success

2515 KB/s (3098485 bytes in 1.203s)

        pkg: /data/local/tmp/Santa Biblia Reina Valera 1960_1.5.3_40.apk

Success

2769 KB/s (4918721 bytes in 1.734s)

        pkg: /data/local/tmp/TalkBack_4.2.0_40200008.apk

Success

1857 KB/s (564672 bytes in 0.296s)

        pkg: /data/local/tmp/Terminal Emulator_1.0.70_71.apk

Success

2266 KB/s (1160352 bytes in 0.500s)

        pkg: /data/local/tmp/Tinycore_3.2.2_22.apk

Success

2221 KB/s (12048716 bytes in 5.296s)

        pkg: /data/local/tmp/WALKMAN_8.3.A.0.2.apk

Success

1667 KB/s (18543284 bytes in 10.859s)

        pkg: /data/local/tmp/WhatsApp_2.12.158_450540.apk

Success

End of Batch File

Press any key to continue . . .

If you need a cross platform solution which also works on multiple connected devices simultaneously (with a bunch of convenience features, like finding adb in default location), you can check out this tool:如果您需要一个跨平台解决方案,它还可以同时在多个连接的设备上运行(具有一系列便利功能,例如在默认位置查找 adb),您可以查看此工具:

https://github.com/patrickfav/uber-adb-tools https://github.com/patrickfav/uber-adb-tools

Usage for install安装使用

java -jar uber-adb-tools.jar --install /folder/apks/

控制台展示

Does also uninstall multiple packages with wildcard support.还卸载具有通配符支持的多个包。

Full disclaimer: I am the developer完全免责声明:我是开发者

for file  in ./*.apk;
do
 adb -s deviceserial install $file;
done

Lokenschwar's answer doesn't take apk names containing spaces. Lokenschwar 的答案不采用包含空格的 apk 名称。 This do also names with spaces.这也用空格命名。

ls -1 *.apk | xargs -d \\n -r -n1 -t adb install

If you want to do it on a Mac, put all your APKs in a folder and try this in the Terminal:如果您想在 Mac 上执行此操作,请将所有 APK 放在一个文件夹中,然后在终端中尝试:

for file in apk/*; 
do 
./adb install $file; 
done

For Windows do this:对于 Windows,请执行以下操作:

in CMD inside ur folder path run this:在你的文件夹路径中的 CMD 中运行这个:

dir /s /b > print.txt

Open the text file and rename all enteries from打开文本文件并重命名所有输入

c:\......

to

adb install -r c:\....

the file should look like this : (Assuming you are using Notepad to view your "print.txt" file, press "CTRL+H". This will open the Find and Replace dialog box.该文件应如下所示:(假设您使用记事本查看“print.txt”文件,请按“CTRL+H”。这将打开“查找和替换”对话框。

adb install -r c:\apps\com.ups.mobile.android-2.apk
adb install -r c:\apps\com.vavni.android.battleship-1.apk

Now you need to rename that .txt extension in your "c:\apps\print.txt" to "print.bat".现在您需要将“c:\apps\print.txt”中的 .txt 扩展名重命名为“print.bat”。 You need to have extension shown in windows.您需要在 Windows 中显示扩展名。 Google that if you dont know how to do that谷歌,如果你不知道怎么做

http://forum.xda-developers.com/showthread.php?t=743457 http://forum.xda-developers.com/showthread.php?t=743457

我已经使用一个 SDCard 和 MultiAPKInstaller 在 30 台设备上安装了 10 个 apk 文件(可在 Play 商店中获得:https: //play.google.com/store/apps/details? id=com.bifusimo.multiapkinstaller&hl=pl)。

Use Powershell ISE on Windows 10:在 Windows 10 上使用 Powershell ISE:

  1. Put all *.apk files in a folder (don't use Space in file names)将所有*.apk文件放在一个文件夹中(不要在文件名中使用空格)

  2. Navigate to this folder with导航到此文件夹

    CD "/your/folder/dir"
  3. Type this command:键入此命令:

     (gci -re *.apk).Fullname

    This will return all the apk files with full path这将返回所有具有完整路径的 apk 文件

  4. Copy all list to the Script pan (on the right or bottom) - then Ctrl + A将所有列表复制到 Script pan(在右侧或底部) - 然后Ctrl + A

  5. Press Ctrl + H to open find and replaceCtrl + H打开查找和替换

  6. Replace the path before apk file with "adb install " (it has 1 space in the end)将apk文件前的路径替换为“adb install” (最后有1个空格)

    For example if we have this:例如,如果我们有这个:

     C:/Users/Username/Documents/APK Folder/first.apk C:/Users/Username/Documents/APK Folder/second.apk C:/Users/Username/Documents/APK Folder/third.apk

    After replace:更换后:

     adb install first.apk adb install second.apk adb install third.apk
  7. Select all list again with Ctrl + A使用Ctrl + A再次选择所有列表

  8. Press F8 on the keyboard or Run Selection on the command bar按键盘上的F8或命令栏上的运行选择

    This will install all the apk to the connected device/emulator这会将所有 apk 安装到连接的设备/模拟器

Save the following as a ' something.ps1 '.将以下内容另存为“ something.ps1 ”。 Right Click -> Run with PowerShell .右键单击->使用 PowerShell 运行

$startTime = Get-Date -Format 'yyyy-MM-dd-HH-mm-ss'
$fileNames = Get-ChildItem -Path $scriptPath -Recurse -Include *.apk
$log = foreach ($f in $fileNames) { adb install -r $f }
$log | Out-File installation-$startTime.log

A log file will be generate in the end.最后会生成一个日志文件。 It will contain all error messages.它将包含所有错误消息。

I developed script for Windows which installs all apks to all connected devices:我为 Windows 开发了脚本,它将所有 apk 安装到所有连接的设备:

echo off       
setlocal EnableDelayedExpansion           
for /f "tokens=*" %%f in ('C:\android\sdk\platform-tools\adb.exe devices') do (
for /r %%p in (*.apk) do (
set devicestr=%%f
set apk=%%p
if "!devicestr!"=="!devicestr:List=!" (
for /f "tokens=1" %%d in ("!devicestr!") do (
set deviceid=%%d
echo !deviceid!
echo !apk!
C:\android\sdk\platform-tools\adb.exe -s !deviceid! install !apk!
)
)
)
)

The step by step actions required to execute Alextooter's answer:执行 Alextooter 的答案所需的分步操作:

On windows 10:在 Windows 10 上:

  1. Download adb fastboot here(download link in first post): https://forum.xda-developers.com/showthread.php?t=2317790在此处下载 adb fastboot(第一篇文章中的下载链接): https ://forum.xda-developers.com/showthread.php?t=2317790

Minimal ADB and Fastboot_techbeasts.rar最小的ADB和Fastboot_techbeasts.rar

  1. extract to c:/b/fastboot (for example)解压到 c:/b/fastboot(例如)
  2. open c:/b/fastboot/py_cmd.exe打开 c:/b/fastboot/py_cmd.exe
  3. connect phone to windows via usb通过usb将手机连接到windows

on phone:电话:

  1. settings>About phone>tap build nr or build model near bottom 7 times>that unlocks the developer options.设置>关于手机>在底部附近点击构建nr或构建模型7次>解锁开发者选项。
  2. Settings> developer options>Enable adb debugging设置>开发者选项>启用adb调试
  3. in ADB on windows: type:在 Windows 上的 ADB 中:输入:

adb devices

to see which ones are available.查看哪些可用。

  1. If it says ... unauthorized, unlock phone screen and accept the pc key.如果显示...未经授权,请解锁手机屏幕并接受 pc 密钥。

  2. then if you paste an .apk in c:/b/fastboot/test.apk, the following command installs the app:然后,如果您将 .apk 粘贴到 c:/b/fastboot/test.apk 中,则以下命令将安装该应用程序:

    adb install test.apk adb 安装 test.apk

  3. The following command installs all the apks in a folder:以下命令将所有 apk 安装在一个文件夹中:

    for %f in (C:\your_app_path\*.apk) do adb install "%f"

  4. Note if you have a space in the path you should put the path between quotation marks:请注意,如果路径中有空格,则应将路径放在引号之间:

    for %f in ("c:/b/fastboot/subfolder with space in the name/apks\*.apk") do adb install "%f"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM