2014-07-24 50 views
22

我剛剛安裝了Gitlab作爲我的項目的存儲庫,我想利用他們的Gitlab CI系統。我想在每次提交後自動生成一個分發和調試Apk。我GOOGLE了,但我沒有找到任何教程或類似的情況。如果有人能以某種方式引導我,那會很棒。使用Gitlab生成Android構建CI

謝謝!

+0

我也對它感興趣。 –

回答

13

我剛纔寫了一篇關於how to setup Android builds in Gitlab CI using shared runners的博客文章。

最快的方法是有一個具有以下內容的.gitlab-ci.yml

image: openjdk:8-jdk 

variables: 
    ANDROID_TARGET_SDK: "24" 
    ANDROID_BUILD_TOOLS: "24.0.0" 
    ANDROID_SDK_TOOLS: "24.4.1" 

before_script: 
    - apt-get --quiet update --yes 
    - apt-get --quiet install --yes wget tar unzip lib32stdc++6 lib32z1 
    - wget --quiet --output-document=android-sdk.tgz https://dl.google.com/android/android-sdk_r${ANDROID_SDK_TOOLS}-linux.tgz 
    - tar --extract --gzip --file=android-sdk.tgz 
    - echo y | android-sdk-linux/tools/android --silent update sdk --no-ui --all --filter android-${ANDROID_TARGET_SDK} 
    - echo y | android-sdk-linux/tools/android --silent update sdk --no-ui --all --filter platform-tools 
    - echo y | android-sdk-linux/tools/android --silent update sdk --no-ui --all --filter build-tools-${ANDROID_BUILD_TOOLS} 
    - echo y | android-sdk-linux/tools/android --silent update sdk --no-ui --all --filter extra-android-m2repository 
    - echo y | android-sdk-linux/tools/android --silent update sdk --no-ui --all --filter extra-google-google_play_services 
    - echo y | android-sdk-linux/tools/android --silent update sdk --no-ui --all --filter extra-google-m2repository 
    - export ANDROID_HOME=$PWD/android-sdk-linux 
    - chmod +x ./gradlew 

build: 
    script: 
    - ./gradlew assembleDebug 
    artifacts: 
    paths: 
    - app/build/outputs/ 

這開始了使用Java 8泊塢圖像,然後進行之前下載並安裝Android SDK的必要位的建立運行。我的文章還詳細介紹瞭如何將其構建到Docker鏡像中,並將其託管在Gitlab本身上。

希望有幫助!

更新 - 2017年4月10日

我寫了規範博客文章設立的Android建立在Gitlab CI早在去年十一月'16本作的官方博客Gitlab。包括如何運行測試等的詳細信息。在這裏鏈接。

https://about.gitlab.com/2016/11/30/setting-up-gitlab-ci-for-android-projects/

3

您可以將構建步驟添加到您的GitLab CI項目中,如下所示。

gradle assemble 

enter image description here

這將生成調試和發佈APK的上提交的在推:

/build/outputs/apk/ 

然後,您可以編寫一個腳本來歸檔生成APK的,但是你需要。