【问题标题】:How can I upload all the flavor apks to nexus using gradle?如何使用 gradle 将所有风味 apk 上传到 nexus?
【发布时间】:2016-04-29 15:19:12
【问题描述】:

所以我已经成功使用uploadArchives 任务将 aar 库上传到 Nexus。 我现在想用 apks 做同样的事情,但目前还没有真正做到正确。 我几乎在做同样的事情,但包装不同。但这并不能解决问题。

我现在想知道使用uploadArchives 任务是否真的是这样做的方式,或者我是否应该使用不同的任务。 这是我现在使用的代码,让我上传 aar 库:

uploadArchives {
    repositories {
        mavenDeployer {
            repository(url: getPropertyValue('mUrl')+"/content/repositories/releases/") {
                authentication(userName: getPropertyValue('mUserName'), password: getPropertyValue('mPassword'))
            }

            def version = getPropertyValue('version')
            _productFlavors.each { name, config ->
                def releaseName = name+"Release"
                addFilter(releaseName) { artifact, file ->
                    artifact.attributes.classifier.equals(releaseName)
                }
                pom(releaseName).artifactId = "artifact"
                pom(releaseName).version = version
                pom(releaseName).groupId = "com.example."+name
                pom(releaseName).packaging = "apk"
            }
        }
    }
}

【问题讨论】:

    标签: android maven gradle nexus


    【解决方案1】:

    有点晚了,但我设法使用旧的普通 httpclient 让它工作。

    def uploadToRepository(File file, String folder, String url, String userName, String password){
    if(url != null && !url.isEmpty()){
        def client = new DefaultHttpClient()
        def post = new HttpPost("${url}/content/repositories/releases/${folder}/myapk.apk");
        def entity = new MultipartEntity()
        def fileBody = new FileBody(file, "application/vnd.android.package-archive", file.name)
        entity.addPart("file", fileBody)
        post.entity = entity
    
        def basicAuthString = "Basic " + "${userName}:${password}".bytes.encodeBase64().toString()
        post.addHeader('Authorization', basicAuthString);
    
        post.setEntity(entity);
        def response = client.execute(post);
        if(response.getStatusLine().getStatusCode() == 201)
            println "${file.name} uploaded"
    }
    }
    
    uploadArchives {
        repositories {
            mavenDeployer {
                def version = getPropertyValue('version')
                def buildVersion = ''
    
                _productFlavors.each { name, config ->
                    def releaseName = name+"Release"
                    addFilter(releaseName) { artifact, file ->
                        artifact.attributes.classifier.equals(releaseName)
                    }
                    def fileName = "${project.buildDir}\\outputs\\apk\\something.app-${name}-release.apk"
                    def file = new File(fileName)
                    uploadToRepository(
                            file,
                            "com/something/${name.replaceAll('_','/')}/something/${version+buildVersion}/",
                            getPropertyValue('mUrl'),
                            getPropertyValue('mUserName'),
                            getPropertyValue('mPassword')
                    )
                }
            }
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2018-09-21
      • 2015-01-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-05
      • 1970-01-01
      • 1970-01-01
      • 2015-04-22
      相关资源
      最近更新 更多