Gradle脚本中执行命令行报错
* What went wrong:
Execution failed for task ':app:installDebug'.
> java.io.IOException: Cannot run program "adb": error=2, No such file or directory
adb shell monkey -p ${applicationId} -c android.intent.category.LAUNCHER 1
String execCommand(command) {
println "execCommand = [$command]"
Runtime runtime = Runtime.getRuntime()
Process p = runtime.exec(command)
InputStream fis = p.getInputStream()
InputStreamReader isr = new InputStreamReader(fis)
BufferedReader br = new BufferedReader(isr)
String line = null
StringBuilder sb = new StringBuilder()
while ((line = br.readLine()) != null) {
sb.append(line)
}
br.close()
isr.close()
fis.close()
def result = sb.toString()
println "result = [$result]"
if (result.contains("error")) {
throw new IllegalStateException(result)
}
return result
}
当前android gradle插件版本为4.2.2
classpath 'com.android.tools.build:gradle:4.2.2'
gradeWrapper配置为6.7.1
#Wed Aug 07 12:29:59 CST 2024
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https://services.gradle.org/distributions/gradle-6.7.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
将
gradle-6.7.1-bin
改为
gradle-7.2-bin