gpt4 book ai didi

android - gradle任务将在使用AS同步时运行

转载 作者:行者123 更新时间:2023-12-03 05:34:57 25 4
gpt4 key购买 nike

我在app / build.gradle中创建了一个像这样的代码的依赖项assembleRelease,当我使用AS同步时收到FileNotFoundException错误

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
}

当我同步gradle时代码将运行?
我希望代码在执行 gradlew push时运行
我该怎么办

最佳答案

尝试在任务的第一部分使用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")
}

关于android - gradle任务将在使用AS同步时运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56966727/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com