【问题标题】:Gradle Upload android application apk to maven repo (nexus)Gradle 将 android 应用程序 apk 上传到 maven repo (nexus)
【发布时间】:2015-01-31 00:37:58
【问题描述】:

我正在尝试创建一个 CI 版本,用于构建 Android 应用的发布版本,并将生成的 apk 上传到 maven sonatype nexus 存储库。

当我运行 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 插件定义了这些工件:

artifacts {
    archives androidSourcesJar
    archives androidJavadocsJar
}

也许我应该在 build/outputs/apk/app-release.apk 中添加一个文件工件?

【问题讨论】:

    标签: android maven gradle pom.xml nexus


    【解决方案1】:

    我尝试了上述解决方案,但当 Jenkins 尝试将 apk 文件上传到我们的 nexus 存储库时,我总是遇到“apk 文件不存在”的问题。 在 gradle 插件的文档中,路径以“build”文件夹开头。 (https://docs.gradle.org/current/userguide/artifact_management.html)
    我试图向路径注入一些环境变量,但詹金斯总是抱怨“找不到文件”。我想出了这个解决方案,它很有效。

    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
    }
    

    【讨论】:

      【解决方案2】:

      我们使用 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
      }
      

      【讨论】:

      • 这会将“apk”“压缩”到“zip”文件中。运行“unzip googlePlay.apk”显示“apk”中有一个“apk”。尝试“adb isntall googlePlay.apk”不起作用。
      猜你喜欢
      • 2018-09-21
      • 1970-01-01
      • 1970-01-01
      • 2020-12-09
      • 2019-02-02
      • 2013-12-22
      • 1970-01-01
      • 1970-01-01
      • 2012-04-24
      相关资源
      最近更新 更多