jenkins配置android自動打包平臺

yinnnnnnn發表於2018-06-30

目的

採用jenkins,關聯git,自動拉取最新程式碼,自動打包Android apk包,一方面解放開發打包慢的問題,另一方面方便測試打包迴歸,節省人力。
整個搭建過程遇到比較多小問題,後面都一一解決,本文做個記錄。

搭建流程

這裡寫圖片描述

配置java環境

這個略過

gradle安裝

apt install gradle

下載sdkmanager

https://developer.android.com/studio/#downloads

android sdk安裝

./sdkmanager –list

android sdk安裝

./sdkmanager “platform-tools” “platforms;android-26” “build-tools;27.0.3” “ndk-bundle”

jenkins配置 ANDROID_HOME

其他部落格文章有

licences同意

安裝過程提示licenses沒有同意,找到一個解決方案。

解決方案:https://stackoverflow.com/questions/38096225/automatically-accept-all-sdk-licences
yes | sdkmanager –licenses

root@iZuf68ausnohve9zzvan1lZ:~/.jenkins/workspace/android-autobuild# ./gradlew 

> Configure project :MPChartLib 
File /root/.android/repositories.cfg could not be loaded.
Checking the license for package Android SDK Platform 27 in /data/android-sdk/licenses
Warning: License for package Android SDK Platform 27 not accepted.
Checking the license for package Android SDK Platform 27 in /data/android-sdk/licenses
Warning: License for package Android SDK Platform 27 not accepted.
Project evaluation failed including an error in afterEvaluate {}. Run with --stacktrace for details of the afterEvaluate {} error.


FAILURE: Build failed with an exception.

* Where:
Build file '/root/.jenkins/workspace/android-autobuild/MPChartLib/build.gradle' line: 61

* What went wrong:
A problem occurred evaluating project ':MPChartLib'.
> Failed to install the following Android SDK packages as some licences have not been accepted.
     platforms;android-27 Android SDK Platform 27
  To build this project, accept the SDK license agreements and install the missing components using the Android Studio SDK Manager.
  Alternatively, to transfer the license agreements from one workstation to another, see http://d.android.com/r/studio-ui/export-licenses.html

  Using Android SDK: /data/android-sdk

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 2s

編譯包

./gradlew tasks
./gradlew assembleDebug

編譯測試包

./gradlew assembleDebug –stacktrace

版本號自動遞增

每次自動打包,版本號自動遞增,實現:

http://devdeeds.com/auto-increment-build-number-using-gradle-in-android/

相關文章