连接到Linux系统时,自动在Android设备上安装多个应用程序 [英] Automatically installing multiple apps on Android devices when connected to a linux system

查看:127
本文介绍了连接到Linux系统时,自动在Android设备上安装多个应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用Ubuntu 14.04和 adb 编写了一些脚本来自动配置100台Android智能手机.为此,我使用了 udev 规则来确定USB设备是否已连接到PC,如果是这种情况,我会调用脚本以在设备上安装一些应用程序.

I had written some scripts using Ubuntu 14.04 and adb to automatically configure 100´s of Android smartphones. To achieve that I used an udev rule to identify if an USB device is attached to the pc and if that's the case I call my scripts to install some apps onto the devices.

到目前为止,还算不错,但是存在一些问题.目前,我们同时连接5台设备,但是经常发生的情况是,其中一台设备上没有安装一个或多个应用程序.它不遵循模式,而是随机发生.有时,计算机的性能也会在一天中下降.

So far, so good but there are some problems. At the moment we are connecting 5 devices at the same time, but it happens quite often that on one of the devices one ore more apps are not being installed. It does not follow a pattern, it just happens randomly. Sometimes also the performance of the computer decreases during the day.

这是我的 udev 规则:

ACTION=="add", ENV{DEVTYPE}=="usb_device", ATTRS{idVendor}!="1d6b", ATTRS{idVendor}!="203a", ATTRS{idVendor}=="****", ATTRS{idProduct}=="****", RUN+="/usr/local/bin/selectDevices.sh"

/usr/local/bin/中的第一个脚本,用于标识应安装应用程序的设备

The first script in /usr/local/bin/ to identify the devices on witch the apps should be installed

#!/bin/bash

sleep 2
Pid=/home/android/Schreibtisch/PID

for DEVICE in `adb devices | tail -n +2 | grep device | awk '{print $1}'`;
do

  if [ ! -f $Pid/$DEVICE.pid ];
  then

    touch $Pid/$DEVICE.pid
    sh /usr/local/bin/touchDevices.sh $DEVICE

  fi

done

以及安装应用程序的最后一个脚本

and the last script to install the apps

#!/bin/bash
cd /home/android/Desktop/Apps

for APK in $(ls *.apk);
do
    adb -s $1 install $APK
done

修改1:我已经尝试过,就像Alex P.建议的那样,或者是在我对他的回答的解释中.将序列号传递给tmp脚本,tmp脚本正在使用现在调用实际的安装脚本.在安装脚本启动之前,它会休眠2秒钟.但是问题仍然存在.也许我需要记录安装过程中发生的情况,但此刻我还不知道该怎么做.

Edit 1: I´ve tried it like Alex P. suggested it or in my interpretation of his answer. Pass the serial to a tmp script and the tmp script is calling the actual installation script with at now. Before the installation script starts it sleeps 2 seconds. But the problems still exist. Maybe I need to log what's happening during the installation but at the moment I have no clue how to do that.

修改2:一段时间后,我认为我发现了一些东西,但我仍然不知道为什么.我认为当两个设备要同时安装一个应用程序时,adb会出现问题.我管理它来接收一条错误消息,例如 rm失败/data/local/tmp/foo.apk,没有这样的文件或目录.之后,我切换到首先将软件包复制到设备,然后使用Shell软件包管理器安装它们,但仍然没有解决方案.

Edit 2: After some time I think I found something but I still have no idea why. I think adb has problems when two devices want to install one app at the same time. I Managed it to receive an error message like rm failed for /data/local/tmp/foo.apk, No such file or directory. After that I switcht to first copy the Package to the devices and then install them with the shell package manager, but still no solution.

推荐答案

我运行多个linux系统,这些系统配置为在设备枚举上自动运行 adb fastboot 命令,该命令可处理数百个每天的Android设备连接数.根据我的经验,我为您提供以下建议:

I run multiple linux systems configured to automatically run adb and fastboot commands on device enumeration which process hundreds of Android device connections per day without a hitch. Based on my experience I have the following advice for you:

  • 您应在枚举设备后等待几秒钟,然后再执行发送任何 adb 命令
  • 您不应直接根据 udev 规则运行任何长时间运行的进程.您现在可以使用 命令将 adb安装命令与 udev
  • 解耦"
  • 无需使用 adb设备即可获取序列号.让您的 udev 规则将其作为参数提供给脚本.
  • sh 就足够的情况下,无需使用 bash
  • 尽可能使用完整路径
  • you should wait couple of seconds after device enumeration before sending any adb commands
  • you should not run any long running processes directly from udev rule. You can use at now command to "decouple" your adb install commands from udev
  • there is no need to use adb devices to get the serial number. Let your udev rule to provide it to your script as a parameter.
  • no need to use bash where sh is enough
  • use full paths where possible

您的安装脚本应如下所示:

Your install script should look like this:

APKDIR="/full/path/to/apks"
PIDDIR="/full/path/to/pid"
ADB="/full/path/to/adb -s usb:$1"

if [ ! -f $PIDDIR/$2.pid ]; then
    touch $PIDDIR/$2.pid
    CMD="sleep 5"
    for APK in $APKDIR/*.apk; do CMD="$CMD; $ADB install $APK"; done
    echo "$CMD" | at -M now 2>/dev/null
fi

将对您的安装脚本的调用添加到 udev 规则的末尾:

Add the call to your install script to the end of the udev rule:

,RUN + ="/bin/sh/full/path/to/the/script.sh%k $ env {ID_SERIAL_SHORT}"

如果此设置仍然无法产生稳定的结果,请尝试增加脚本中的 持续时间.

If this setup still does not produce stable results - try increasing the sleep duration in the script.

这还有助于为您的 udev 规则分配更大的数字(90 +)

Also it helps to assign bigger number (90+) to your udev rule

这篇关于连接到Linux系统时,自动在Android设备上安装多个应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆