i create a task dependsOn assembleRelease like this code in app/build.gradle, and get an FileNotFoundException
error when i use AS sync
task push(type: Exec, dependsOn: ['assembleRelease']) {
println 'push invoke'
def apkDir = "${project.projectDir.absolutePath}/build/outputs/plugin/release/"
def apkName = ""
fileTree(apkDir).visit { FileVisitDetails details ->
println "${details.name}"
//只取第一个apk
if (apkName.endsWith(".apk")) {
apkName = details.name
details.stopVisiting()
}
}
if (apkName.isEmpty()) throw new FileNotFoundException("apk file not found,please invoke 'assemblePlugin' first")
workingDir project.projectDir
commandLine 'adb', 'push', "${project.projectDir.absolutePath}/build/outputs/plugin/release/{$apkName}", '/sdcard/Demo_plugin_1.apk'
ignoreExitValue true
}
the code will run when I sync gradle? and I want the code will run when excute gradlew push
what should I do
try to use doFirst{ } block for the first part of the task:
doFirst {
println 'push invoke'
def apkDir = "${project.projectDir.absolutePath}/build/outputs/plugin/release/"
def apkName = ""
fileTree(apkDir).visit { FileVisitDetails details ->
println "${details.name}"
//只取第一个apk
if (apkName.endsWith(".apk")) {
apkName = details.name
details.stopVisiting()
}
}
if (apkName.isEmpty()) throw new FileNotFoundException("apk file not found,please
invoke 'assemblePlugin' first")
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.