如何从Android Gradle构建FTP文件?

时间:2013-06-19 21:37:26

标签: android ftp gradle

我正在尝试在Gradle构建后对已签名的APK进行FTP。我已经添加了将对APK进行签名的新构建配置,但我仍然试图弄清楚如何调用FTP任务。

我在section 59.6找到了一个正式的样本,但它抱怨它无法解析依赖org.apache.ant:ant-commons-net:1.8.4。所以显然我在这里遗漏了一些明显的东西,比如在哪里放一个给定的jar文件或引用它,虽然我认为maven会处理这类事情?

作为参考,这里是链接的示例,它失败并显示有关依赖项的消息:

configurations {
    ftpAntTask
}

dependencies {
    ftpAntTask("org.apache.ant:ant-commons-net:1.8.4") {
        module("commons-net:commons-net:1.4.1") {
            dependencies "oro:oro:2.0.8:jar"
        }
    }
}

task ftp << {
    ant {
        taskdef(name: 'ftp',
                classname: 'org.apache.tools.ant.taskdefs.optional.net.FTP',
                classpath: configurations.ftpAntTask.asPath)
        ftp(server: "ftp.apache.org", userid: "anonymous", password: "me@myorg.com") {
            fileset(dir: "htdocs/manual")
        }
    }
}

此操作失败并显示以下消息:

> Could not find org.apache.ant:ant-commons-net:1.8.4.

这是我完整的gradle.build文件,删除了一些敏感信息:

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.4'
    }
}

apply plugin: 'android'

dependencies {
    compile files('libs/android-support-v4.jar')
}

android {
    compileSdkVersion 17
    buildToolsVersion "17.0.0"

    defaultConfig {
        minSdkVersion 14
        targetSdkVersion 17
    }

    signingConfigs {
        signed {
            storeFile file("(removed)")
            storePassword "(removed)"
            keyAlias "(removed)"
            keyPassword "(removed)"
        }
     }

    buildTypes {
        signed {
            debuggable false
            jniDebugBuild false
            signingConfig signingConfigs.signed
        }
    }
}

configurations {
    ftpAntTask
}

dependencies {
    ftpAntTask("org.apache.ant:ant-commons-net:1.8.4") {
        module("commons-net:commons-net:1.4.1") {
            dependencies "oro:oro:2.0.8:jar"
        }
    }
}

task ftp << {
    ant {
        taskdef(name: 'ftp',
                classname: 'org.apache.tools.ant.taskdefs.optional.net.FTP',
                classpath: configurations.ftpAntTask.asPath)
        ftp(server: "(removed)", userid: "(removed)", password: "(removed)", remoteDir: "(removed)") {
            fileset(dir: "(removed)") {
                include(name: "(removed)")
            }
        }
    }
}

2 个答案:

答案 0 :(得分:2)

您没有声明可用于解析声明的工件的存储库。尝试将以下代码段添加到build.gradle文件中:

repositories{
    mavenCentral()
}

欢呼声,

答案 1 :(得分:0)

您还可以使用支持FTP的本机ant get任务,无需外部依赖:

  ant {
    get(src: "ftp://<hostname>/remote/path/to/file.jar", dest: "/local/path/to/file", username: 'anonymous', password: 'anonymous')
  }