gpt4 book ai didi

android-studio - Gradle:构建后如何通过 FTP 上传发布的 APK 文件

转载 作者:行者123 更新时间:2023-12-03 17:59:43 25 4
gpt4 key购买 nike

我想在构建发布版本时自动将 APK 文件上传到服务器。

为此,我将使用 FTP 协议(protocol)。

我是关于 Gradle 脚本的新手。我使用这两个问题( thisthis )作为基础,但有些事情没有解决。

谁能指出它是什么?

这是代码(在 build.gradle 上):

gradle.buildFinished {
println("---- Build finished. This message appears ----")
task ftp << {
project.logger.lifecycle('-- This message does not appear --')
ant {
taskdef(name: 'ftp',
classname: 'org.apache.tools.ant.taskdefs.optional.net.FTP',
classpath: configurations.ftpAntTask.asPath)
def destination = "ftp://xxxxxxxxxx@xxx.surftown.com/xxxxx/"
def source = null
android.applicationVariants.all { variant ->
if ( (variant.name).equals("release") ) {
variant.outputs.each { output ->
source = output.outputFile
}
}
}
def user = 'xxxxxxxxx'
def pass = 'xxxxxxxxx'
ftp(server: source, userid: user, password: pass, remoteDir: destination)
}
}

最佳答案

gradle.buildFinished注册一个在构建结束时执行的钩子(Hook)。在您的情况下,它只是创建 ftp任务。

如果 build涉及任务:

build.finalizedBy(ftp)

否则,要确保无论调用什么任务它都能正常工作:
tasks.all*.finalizedBy(ftp)

顺便说一句,它在您的第一个链接的第一个答案的评论部分中进行了解释。

关于android-studio - Gradle:构建后如何通过 FTP 上传发布的 APK 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49261892/

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