Gradle上传android应用程序apk到maven repo(nexus)

tal*_*ari 8 android nexus gradle pom.xml maven

我正在尝试创建一个CI构建,构建一个Android应用程序的发布版本,并将生成的apk上传到maven sonatype nexus repo.

当我运行assembleRelease时,apk生成,签名,运行proguard,位于build/outputs/apk/app-release.apk

为了上传到nexus,我使用了这个gradle插件:https: //github.com/chrisbanes/gradle-mvn-push 有一点不同,我使用了POM_PACKAGING = apk

我运行:gradle uploadArchives并且它工作正常,它确实将apk上传到nexus,但它与build/outputs/apk/app-release.apk(不同的创建日期)中的文件不同.

意思是它要么做任何assembleRelease,要么只是归档源,但是错过了一些Android应用程序所需的一些动作.

gradle插件定义了这些artificats:

artifacts {
    archives androidSourcesJar
    archives androidJavadocsJar
}
Run Code Online (Sandbox Code Playgroud)

也许我应该添加一个文件工件来构建/输出/ apk/app-release.apk?

小智 5

我尝试了上面提到的解决方案但是当Jenkins试图将apk文件上传到我们的nexus存储库时,我总是有一个"apk文件不存在"的问题.在gradle插件的文档中,路径以"build"文件夹开头.(https://docs.gradle.org/current/userguide/artifact_management.html)
我试图向路径注入一些env变量,但jenkins总是抱怨"找不到文件".我提出了这个解决方案,它只是起作用.

uploadArchives {
repositories {
        mavenDeployer {
            repository(url: "https://repo.domain.com/content/repositories/snapshots") {
                authentication(userName: nexususername, password: nexuspassword)
            }

            pom.project {
                version "0.0.1-SNAPSHOT"
                artifactId "android-artifact"
                name "android-name"
                groupId "com.domain.foo.bar"
            }
        }
    }
}


    // /data/jenkins_work/NAME_OF_THE_BUILD_JOB/artifact/app/build/outputs/apk/app-debug.apk
def apk = file('app/build/outputs/apk/yourapp.apk')

artifacts {
    archives apk
}
Run Code Online (Sandbox Code Playgroud)


van*_*rra 3

我们使用 gradle 将 APK 文件发布到本地 Nexus 存储库。这就是我想出的办法。此示例演示了如何使用“googlePlay”构建风格。

// make sure the release builds are made before we try to upload them.    
uploadArchives.dependsOn(getTasksByName("assembleRelease", true))

// create an archive class that known how to handle apk files.
// apk files are just renamed jars.
class Apk extends Jar {
    def String getExtension() {
        return 'apk'
    }
}

// create a task that uses our apk task class.
task googlePlayApk(type: Apk) {
    classifier = 'googlePlay'
    from file("${project.buildDir}/outputs/apk/myApp-googlePlay-release.apk")
}

// add the item to the artifacts
artifacts {
    archives googlePlay
}
Run Code Online (Sandbox Code Playgroud)