2014-12-02 88 views
6

我正在嘗試創建一個構建Android應用程序發佈版本的CI構建,並將結果apk上傳到maven sonatype nexus回購。Gradle上傳android應用程序apk到maven回購(nexus)

當我運行assembleRelease,生成APK,簽約,運行proguard的,它位於在建/輸出/ APK/APP-release.apk以上傳到關係

,我用這個gradle這個插件: https://github.com/chrisbanes/gradle-mvn-push 有一個區別,那我用POM_PACKAGING = APK

我運行:gradle這個uploadArchives 並能正常工作,但它上傳APK的Nexus,但它不是同一個文件中生成/輸出/apk/app-release.apk(不同的創建日期)。

這意味着它可以執行任何assembleRelease,或者只是歸檔源代碼,但是會漏掉一些android應用程序需要的操作。

的gradle這個插件定義了這些artificats:

artifacts { 
    archives androidSourcesJar 
    archives androidJavadocsJar 
} 

也許我應該添加一個文件神器打造/輸出/ APK/APP-release.apk?

回答

0

我們使用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 
} 
+0

這將在「zip」文件中「zip」「apk」。運行「解壓縮googlePlay.apk」顯示「apk」中有一個「apk」。試圖「adb isntall googlePlay.apk」不起作用。 – 2015-03-04 20:45:51

5

我想提到的解決方案,但我始終有一個「apk文件不存在」時,詹金斯試圖將APK文件上傳到我們的關係資源庫的問題。 在gradle插件的文檔中,路徑以「build」文件夾開頭。 (https://docs.gradle.org/current/userguide/artifact_management.html
我試圖向路徑注入一些env變量,但詹金斯總是抱怨「找不到文件」。我想出了這個解決方案,它很簡單。

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 
}