在 Eclipse 下单击一下即可在多个设备上安装并运行应用程序

发布于 2024-11-10 15:46:19 字数 217 浏览 8 评论 0原文

我想知道是否有一种方法可以在 Eclipse 下单击一下在多个设备/模拟器上安装和运行 Android 应用程序。

当我在多个 (n) 设备上测试布局时,我现在正在执行 n 次 run-as(实际上是 ctrl-F11 快捷键),选择正确的设备,然后检查每个设备上的布局。

如果能够使用单个命令在连接到我的计算机的所有设备上进行安装和启动,那就太棒了。

这样的事情存在吗?

I am wondering if there is a way to install and run an android application on multiple devices/emulator with a single click under Eclipse.

When I am testing a layout on multiple (n) devices I am doing right now n times run-as (ctrl-F11 short cut in fact), choose the correct device and then check my layout on each device.

It would be great to use a single command to install and launch on all devices connected to my computer.

Does a such thing exist?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

三月梨花 2024-11-17 15:46:19

如果您使用 Eclipse,只需执行以下操作:

  1. 打开“项目属性”对话框。
  2. 在“运行/调试设置”下,选择您的项目并进行编辑。
  3. 应弹出另一个对话框,选择“目标”选项卡,选择“在所有兼容设备/AVD 上启动”。

  4. 应用,您应该在运行/调试时安装所有设备。

If you using eclipse, just do below:

  1. open 'project properties' dialog.
  2. under 'Run/Debug settings', select your project and edit.
  3. another dialog should pop up, select 'target' tab, select 'Launch on all compatible devics/AVD's '.

  4. Apply and you should get all of devices install when Run/Debug.

薄凉少年不暖心 2024-11-17 15:46:19

最简单的方法是使用包含几行的批处理文件(或 shell 脚本)

adb -s SERIAL_NO install workspace/YOUR_PROJECT/bin/YOUR_APK.apk

确保 Eclipse 设置为自动构建项目。然后,它不是一键单击,而是关闭:

  • Ctl-Shift-S 保存全部,
  • Alt-TAB 进入命令提示符,
  • 向上箭头 Enter 重新运行脚本。
  • 享受。 5 秒顶;)

The simplest way is to have a batch file (or shell script) with several lines

adb -s SERIAL_NO install workspace/YOUR_PROJECT/bin/YOUR_APK.apk

Make sure that Eclipse is set to build the project automatically. Then, it's not one-click, but close:

  • Ctl-Shift-S to save all,
  • Alt-TAB to get to the command prompt,
  • up arrow enter to rerun the script.
  • Enjoy. 5 seconds tops ;)
撞了怀 2024-11-17 15:46:19

我刚刚完成了 Aleadam 建议我做的脚本。

连接到计算机的每个设备上的一个简单循环,进行安装和启动。

脚本和安装:

#!/bin/bash

if [ $# -lt 3 ] ;then
    echo "usage $0 pathToTheFileToInstall packagename fullPackageActivityName"
    exit 1
fi

FILEPATH=$1
PACKAGE=$2
ACTIVITYNAME=$3

APK=`ls $FILEPATH/*.apk`

installOnSingleDevice(){
    echo "Installing on $DEVICE -------"
    echo "adb -s $1 install -r $APK"
    adb -s $1 install -r $APK 

    echo "adb -s $1 shell am start -n $2/$3"
    adb -s $1 shell am start -n $2/$3
    echo "--------------------------"
}

if [ $? -eq 0 ] ;then
    adb devices | grep device | grep -v attached | cut -f 1 > tmpfile
    while read line; 
    do 
        installOnSingleDevice $line $PACKAGE $ACTIVITYNAME&
    done < tmpfile
    rm tmpfile
else
    echo "No apk at this path (${FILEPATH})"
fi

使用示例:

andinstall ~/workspace/myapp/bin/ fr.openium.myapp fr.openium.myapp.activity.ActivitySplash

I just finished the script Aleadam advice me to do.

A simple loop on each device connected to the computer with install and start.

Script andinstall:

#!/bin/bash

if [ $# -lt 3 ] ;then
    echo "usage $0 pathToTheFileToInstall packagename fullPackageActivityName"
    exit 1
fi

FILEPATH=$1
PACKAGE=$2
ACTIVITYNAME=$3

APK=`ls $FILEPATH/*.apk`

installOnSingleDevice(){
    echo "Installing on $DEVICE -------"
    echo "adb -s $1 install -r $APK"
    adb -s $1 install -r $APK 

    echo "adb -s $1 shell am start -n $2/$3"
    adb -s $1 shell am start -n $2/$3
    echo "--------------------------"
}

if [ $? -eq 0 ] ;then
    adb devices | grep device | grep -v attached | cut -f 1 > tmpfile
    while read line; 
    do 
        installOnSingleDevice $line $PACKAGE $ACTIVITYNAME&
    done < tmpfile
    rm tmpfile
else
    echo "No apk at this path (${FILEPATH})"
fi

Usage example:

andinstall ~/workspace/myapp/bin/ fr.openium.myapp fr.openium.myapp.activity.ActivitySplash
画▽骨i 2024-11-17 15:46:19

您应该能够将 Ant XML 文件添加到 Eclipse 项目中,并使用可以从命令行运行外部程序的 Ant 任务填充它。也许您应该为要运行的每个设备拥有一个单独的任务项,然后包含所有这些设备的父任务。

然后向 Eclipse 项目添加一个自定义构建器步骤,选择 Ant 作为构建器并指向之前添加的 XML 文件(请参阅 此处

我不是 Ant 方面的专家,但在某些时候我需要添加一个自定义任务从 Eclipse 中从我的项目代码构建一个 Jar,以便我可以在每次需要时运行它(例如 此处)。这个过程非常有效。

应该为您执行的 Ant 任务是 Exec: http://ant.apache.org /manual/Tasks/exec.html。您可能想查看http://ant.apache.org/manual/using。 html 作为一个简单的入门。

您的 XML 可能类似于以下内容(不过我还没有尝试过):

<?xml version="1.0"?>
<project name="...use same name as your project for simplicity..." default="runmultidevices">
  <property name="myapk" location="workspace/YOUR_PROJECT/bin/YOUR_APK.apk"/>
  <target name="runmultidevices" description="Run on multiple devices" depends="rundevice1 rundevice2">
  </target>
  <target name="rundevice1" description="Run on device 1">
    <exec executable="adb">
      <arg line="-s SERIAL_NO_1 install ${myapk}" />
    </exec>
  </target>
  <target name="rundevice2" description="Run on device 2">
    <exec executable="adb">
      <arg line="-s SERIAL_NO_2 install ${myapk}" />
    </exec>
  </target>
</project>

为了不手动编写每个项目的包位置,Eclipse 和 Ant 之间似乎没有那么好的集成。您可以尝试以下建议:

  • 使用本机 Ant ${basedir} 属性,如 此处
  • 在调用 Ant 时将 Eclipse 变量作为附加参数传递,如 此处-Dworkspace_loc=${workspace_loc}
  • 访问 Eclipse .project< /code> 来自 Ant 内的文件,使用特定的 XML 解析工具,如 此处

You should be able to add an Ant XML file to your Eclipse project, and fill it with Ant tasks that can run an external program from command line. Probably you should have a separate task item for each device you want to run on, and then a parent task containing all of them.

Then add a single custom builder step to Eclipse project, choosing Ant as builder and pointing to the XML file you added previously (see here)

I'm not a big expert on Ant, but at some point I needed to add a custom task to build a Jar out of my project code from within Eclipse, so that I could run it everytime I needed it (like here). This procedure worked quite well.

The Ant task that should do for you is Exec: http://ant.apache.org/manual/Tasks/exec.html. You might want to have a look at http://ant.apache.org/manual/using.html for a simple starter.

Your XML could be something like the following (I haven't tried it though):

<?xml version="1.0"?>
<project name="...use same name as your project for simplicity..." default="runmultidevices">
  <property name="myapk" location="workspace/YOUR_PROJECT/bin/YOUR_APK.apk"/>
  <target name="runmultidevices" description="Run on multiple devices" depends="rundevice1 rundevice2">
  </target>
  <target name="rundevice1" description="Run on device 1">
    <exec executable="adb">
      <arg line="-s SERIAL_NO_1 install ${myapk}" />
    </exec>
  </target>
  <target name="rundevice2" description="Run on device 2">
    <exec executable="adb">
      <arg line="-s SERIAL_NO_2 install ${myapk}" />
    </exec>
  </target>
</project>

In order to not manually write the package location for each project, there seems to be not such a great integration between Eclipse and Ant. You might try the following suggestions:

  • use the native Ant ${basedir} property as in here
  • pass an Eclipse variable as an additional parameter when invoking Ant as in here: -Dworkspace_loc=${workspace_loc}
  • access Eclipse .project file from within Ant, using a specific XML parsing facility as in here
临走之时 2024-11-17 15:46:19

这是我的解决方案,可以使用两个快捷键 STRG+SSTRG+ALT+F10 在多个设备上轻松构建、安装和启动 Android 应用程序;)

1 。构建 APK

在 Eclipse 中构建 Android 的正常行为是不会创建 APK。但在首选项中可以选择禁用该行为。

  • 窗口->首选项->安卓->构建->跳过包装和除检,直到导出或发布

=>取消选择该选项后,更改代码后只需按 Strg+S 即可创建 APK 文件。

2.安装和启动

要为多个设备安装并自动启动应用程序,我认为最简单的方法是使用命令行和 Windows 批处理脚本:

<!-- language: Batch script -->
:: This five lines are used to minimize the 
:: command lines directly after the start
if not "%minimized%"=="" goto :minimized
set minimized=true
start /min cmd /C "%~dpnx0"
goto :EOF
:minimized

:: Path to the ADB and to the APK file
@set ADB="D:/Android/sdk/platform-tools/adb.exe"
@set APK="D:/workspace_android/SomeApp/bin/SomeApp.apk"

:: AndroidManifest.xml: <manifest package="com.example.appname">
:: The launching activity: <activity android:name=".activities.HomeActivity">
@set ACTIVITY=at.example.appname/.activities.HomeActivity

:: Install APK on all devices
%ADB% devices | tail -n +2 | cut -sf 1 | xargs -iX %ADB% -s X install -r %APK%
:: Launch App on all devices
%ADB% devices | tail -n +2 | cut -sf 1 | xargs -iX %ADB% -s X shell am start -a android.intent.action.MAIN -n %ACTIVITY%

在我的例子中,我有三个设备。为了更快地访问一台设备,我使用了以下代码而不是上面代码中的循环。首先,我在最快的设备上安装并启动应用程序,然后在第二台设备上安装并启动应用程序,依此类推。我确信有更好的方法来代替使用 tail、head 和 xargs,但我对批处理文件了解不多,但它只是运行。 ;)

<!-- language: Batch script -->
:: NEXUS 5
:: This command reinstalls the APK on the Nexus 5 device
%ADB% devices | tail -n +2 | head -n +1 | cut -sf 1 | xargs -iX %ADB% -s X install -r     %APK%
:: This command launch the application on the Nexus 5 device
%ADB% devices | tail -n +2 | head -n +1 | cut -sf 1 | xargs -iX %ADB% -s X shell am start -a android.intent.action.MAIN -n %ACTIVITY%

:: Galaxy Tab
%ADB% devices | tail -n -2 | cut -sf 1 | xargs -iX %ADB% -s X install -r %APK%
%ADB% devices | tail -n -2 | cut -sf 1 | xargs -iX %ADB% -s X shell am start -a android.intent.action.MAIN -n %ACTIVITY%

:: Optimus 3D
%ADB% devices | tail -n +3 | head -n +1 | cut -sf 1 | xargs -iX %ADB% -s X install -r %APK%
%ADB% devices | tail -n +3 | head -n +1 | cut -sf 1 | xargs -iX %ADB% -s X shell am start -a android.intent.action.MAIN -n %ACTIVITY%

获得 Windows 批处理脚本后,创建该文件的快捷方式。右键单击快捷方式文件并选择属性。您可以在其中指定全局快捷键,例如 STRG+ALT+F10

在Eclipse中更改一些代码后,您只需按STRG+S,然后按STRG+ALT+F10,应用程序将最终在所有设备上启动。是的! :)

Here is my solution to easily build, install and launch an Android application on multiple devices with exactly two shortcuts STRG+S and STRG+ALT+F10 ;)

1. Build APK

The normal behavior of an Android Build in Eclipse is, that the APK will not be created. But in the preferences is the option to disabled that behavior.

  • Window -> Preferences -> Android -> Build -> Skip packaging and dexing until export or launch

=> After deselecting that option, only a Strg+S is needed to create the APK file after a change in the code.

2. Install and Launch

To install and automatically launch the app for multiple devices, the easiest way is to use the command line and a Windows Batch script in my opinion:

<!-- language: Batch script -->
:: This five lines are used to minimize the 
:: command lines directly after the start
if not "%minimized%"=="" goto :minimized
set minimized=true
start /min cmd /C "%~dpnx0"
goto :EOF
:minimized

:: Path to the ADB and to the APK file
@set ADB="D:/Android/sdk/platform-tools/adb.exe"
@set APK="D:/workspace_android/SomeApp/bin/SomeApp.apk"

:: AndroidManifest.xml: <manifest package="com.example.appname">
:: The launching activity: <activity android:name=".activities.HomeActivity">
@set ACTIVITY=at.example.appname/.activities.HomeActivity

:: Install APK on all devices
%ADB% devices | tail -n +2 | cut -sf 1 | xargs -iX %ADB% -s X install -r %APK%
:: Launch App on all devices
%ADB% devices | tail -n +2 | cut -sf 1 | xargs -iX %ADB% -s X shell am start -a android.intent.action.MAIN -n %ACTIVITY%

In my case I have three devices. For faster access to one device, I used the following code instead of the loop in upper code. First, I install and launch the app on the fastest device and after that on the second and so on. I am sure there are better ways instead of using tail, head and xargs, but I don't know that much about Batch files, but it just runs. ;)

<!-- language: Batch script -->
:: NEXUS 5
:: This command reinstalls the APK on the Nexus 5 device
%ADB% devices | tail -n +2 | head -n +1 | cut -sf 1 | xargs -iX %ADB% -s X install -r     %APK%
:: This command launch the application on the Nexus 5 device
%ADB% devices | tail -n +2 | head -n +1 | cut -sf 1 | xargs -iX %ADB% -s X shell am start -a android.intent.action.MAIN -n %ACTIVITY%

:: Galaxy Tab
%ADB% devices | tail -n -2 | cut -sf 1 | xargs -iX %ADB% -s X install -r %APK%
%ADB% devices | tail -n -2 | cut -sf 1 | xargs -iX %ADB% -s X shell am start -a android.intent.action.MAIN -n %ACTIVITY%

:: Optimus 3D
%ADB% devices | tail -n +3 | head -n +1 | cut -sf 1 | xargs -iX %ADB% -s X install -r %APK%
%ADB% devices | tail -n +3 | head -n +1 | cut -sf 1 | xargs -iX %ADB% -s X shell am start -a android.intent.action.MAIN -n %ACTIVITY%

After having the Windows Batch script, create a shortcut of that file. Right click the shortcut file and select properties. There you can specify a global shortcut key for example STRG+ALT+F10.

After changing some code in Eclipse, you only have to press STRG+S and then STRG+ALT+F10 and the app will be finally launched on all devices. Yeah! :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文