问题
I had been trying to build my test project jar file using gradle instead of ant with uiautomator android but I am getting BUILD FAILED error.
![](https://www.eimg.top/images/2020/03/25/95c3a8b5ca468a463b95999639ee43f4.png)
I had referred using gradle with uiautomator android form here - http://wiliamsouza.github.io/#/2013/10/30/android-uiautomator-gradle-build-system
I had used the following commands :
android create uitest-project -n ProjectName -t 46 -p D:\Android_Workspace\Smriti\ProjectName
set ANDROID_HOME=D:\Android Development\android-sdk
cd D:\Android_Workspace\Smriti\ProjectName
gradle build //here I get build failed error
My gradle-properties is as shown below :
androidSdkHome = D:/Android Development/android-sdk
androidSdkTarget = android-19
androidSdkBuildToolsDir = build-tools/19.0.0
and build.gradle is -
apply plugin: 'java'
apply plugin: 'idea'
sourceCompatibility = 1.5
targetCompatibility = 1.5
version = '0.1'
project.ext {
dexDir = new File('build/dex')
distDir = new File('./dist')
}
repositories {
mavenCentral()
}
dependencies {
compile fileTree(dir: androidSdkHome + '/platforms/' + androidSdkTarget, include: '*.jar')
compile group: 'junit', name: 'junit', version: '4.11'
}
jar {
doLast {
tasks.dex.execute()
}
}
task dex(dependsOn: jar, type:Exec) {
println 'Building dex...'
project.dexDir.mkdirs()
workingDir '.'
commandLine androidSdkHome + '/' + androidSdkBuildToolsDir + '/' + 'dx', '--dex', '-- no-strict', '--output=' + buildDir +'/dex/' + project.name + '.jar', jar.archivePath
doLast {
tasks.dist.execute()
}
}
task dist(dependsOn:dex, type:Copy) {
project.distDir.mkdirs()
from(project.dexDir)
into(project.distDir)
include('*.jar')
}
Any help would be appreciated.
Thanks.
回答1:
It might be because the sdk folder name containing a space. Change the Android sdk folder from D:\Android Development to any other folder with no space in them,or rename the folder to Android_Development
回答2:
I have faced this issue on windows PC.
I have a custom Gradle task to create dex files and I was running it with commandLine command. The issue was it cannot identify dx tool in android SDK home.
So I have changed the path in commandLine to include .bat
at the end of dx tool in my build.gradle file.
commandLine androidSdkHome + '/' + androidSdkBuildToolsDir + '/' + 'dx.bat', '--dex', '--no-strict', '--output=' + buildDir +'\\' + project.name + '.jar', jar.archivePath
来源:https://stackoverflow.com/questions/21771425/build-failed-gradle-with-uiautomator-android