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>
adb push <jar_path> /data/local/tmp
adb shell uiautomator runtest <jar_name> -c <main_class>
[checkenv] Android SDK Tools Revision 24.1.2
[checkenv] Installed at C:\Android
[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] Creating output directories if needed...
[dex] input: <test_path>\bin\classes
[dex] Converting compiled files and external libraries into <test_path>\bin\classes.dex...
[dx] no classfiles specified
C:\Android\tools\ant\uibuild.xml:198: null returned: 1
Total time: 1 second
Well I finally figured it out.
From the command line, in the main folder of the project (where you can find gradlew.bat file) run the following commands
install on device:
(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)
If you want to know other options you may have run
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>));
Where shell_command depends on the operating system (the command for the command line):
- Windows: cmd /C - Unix-based: /bin/sh -c