从命令行构建UiAutomator 2.0 [英] Build UiAutomator 2.0 from command line

查看:83
本文介绍了从命令行构建UiAutomator 2.0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过命令行构建,安装和运行UiAutomator项目的测试.

I want to build, install and run the tests of a UiAutomator project through the command line.

在以前的版本中,我正在做

In the previous version I was doing:

android create uitest-project -n <project_name> -p <project_path> -t <target_id>
ant build

建立然后

adb push <jar_path> /data/local/tmp

最后安装

adb shell uiautomator runtest <jar_name> -c <main_class>

但是,现在我被困在建筑部分.

结果是

-check-env:
  [checkenv] Android SDK Tools Revision 24.1.2                                    
  [checkenv] Installed at C:\Android                                                                                                                             
-build-setup:                                                                   
[getbuildtools] Using latest Build Tools: 22.0.0                                     
    [echo] Resolving Build Target for AndroidExplorerTester...                 
[getuitarget] Project Target:   Android 5.0.1                                   
[getuitarget] API level:        21                                                   
    [echo] ----------                                                               
    [echo] Creating output directories if needed...                                                                                                            
-pre-compile:                                                                                                                                                   
compile:                                                                                                                                                        
-post-compile:                                                                                                                                                  
-dex:                                                                                 
    [dex] input: <test_path>\bin\classes                                                                          
    [dex] Converting compiled files and external libraries into <test_path>\bin\classes.dex...
     [dx] no classfiles specified                                                                                                                             
BUILD FAILED                                                                    
C:\Android\tools\ant\uibuild.xml:198: null returned: 1                                                                                                          
Total time: 1 second             

自新版UiAutomator以来,我不知道现在是否有更好的方法.

I don't know if there is a better way to do it now since the new version of UiAutomator.

注意:我不知道这是否重要,但是我以前使用过Eclipse,现在我使用的是IntelliJ(如果您更喜欢大声笑,请使用Android Studio)

Note: I don't know if it matters but I was using Eclipse before and now I'm using IntelliJ (Android Studio if you prefer lol)

推荐答案

好,我终于弄清楚了.

在命令行的项目主文件夹(可以找到gradlew.bat文件)中,运行以下命令

From the command line, in the main folder of the project (where you can find gradlew.bat file) run the following commands

构建:

.\gradlew.bat assembleDebug

在设备上安装:

.\gradlew.bat installDebug

(如果您希望Release版本只是将Debug替换为Release,我没有尝试过,但是选项存在,所以我想它们可以工作)

(if you want Release version just replace Debug for Release, I didn't try it but the options exist and so I suppose they work)

运行:

.\gradlew.bat connectedCheck

如果您想知道其他选项,则可能已经运行

If you want to know other options you may have run

.\gradlew.bat tasks

其他信息

要以编程方式(Java)使用Runtime.getRuntime().exec(字符串命令,String [] envp,文件目录).例如,

To do it programmatically (Java) use Runtime.getRuntime().exec(String command, String[] envp, File dir). For instance,

Runtime.getRuntime().exec(shell_command + " <path_to_test_folder>\gradlew.bat assembleDebug", null, new File(<path_to_test_project>));

shell_command取决于操作系统(命令行的命令)的地方:

Where shell_command depends on the operating system (the command for the command line):

- Windows: cmd /C
- Unix-based: /bin/sh -c

这篇关于从命令行构建UiAutomator 2.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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