我在app / build.gradle中创建了一个依赖于此类代码的任务dependOn assembleRelease,当我使用AS同步时出现arr[::-1]
错误
FileNotFoundException
当我同步gradle时代码会运行吗?
我希望代码在执行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
}
时运行
我该怎么办
答案 0 :(得分:0)
尝试在任务的第一部分使用doFirst {}块:
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")
}