在使用Jenkins
配置Android項目
的時候遇到了一些坑,總結下:javascript
##沒有gradle.properties文件java
example/bulid.gradle
FAILURE: Build failed with an exception.android
- Where:
Build file '/Users/Shared/Jenkins/Home/jobs/android- crop/workspace/build.gradle' line: 12- What went wrong:
A problem occurred evaluating root project 'workspace'.
Could not find property 'VERSION' on root project 'workspace'.
Android Studio
打開一個項目的時候默認會生成gradle.properties
,在使用Jenkins
集成的時候使用的是gradle assembleRelease
命令,不會自動生成gradle.properties
的,就出現了上面的錯誤。解決方案:在項目根目錄添加一個gradle.properties
:git
VERSION=1.0.1
VERSION_CODE=1
signing.keyId=
signing.secretKeyRingFile=
signing.password=
sonatypeUsername=jdamcd
sonatypePassword=複製代碼
##沒法使用.ssh中的private keyssh
clone
項目的時候沒法使用.ssh
中的private key
。Jenkins
的時候會新建了一個用戶(jenkins),jenkins用戶沒有權限讀取~/.ssh
的權限。 Add credentials
手動輸入private key的內容:##構建項目權限不足工具
錯誤信息:gradle
- What went wrong:
java.io.IOException: Permission denied
Permission denied
錯誤分析:形成這個問題的緣由是由於給予jenkins
用戶的權限不足,沒法操做jenkins
目錄。ui
解決方案: 給jenkins用戶
足夠的權限this
sudo chown -R jenkins /var/lib/jenkins/複製代碼
##沒有設置sdk的目錄lua
錯誤分析:local.properties
一樣的也是由Android Studio
中自動根據環境變量生成的,在使用gradle build
的時候也是沒法自動建立的。
解決方案:在項目根目錄定義一個local.properties
並指定sdk.dir
爲Android SDK的位置。
## This file is automatically generated by Android Studio.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
#
# This file must *NOT* be checked into Version Control Systems,
# as it contains information specific to your local configuration.
#
# Location of the SDK. This is only used by Gradle.
# For customization when using a Version Control System, please read the
# header note.
#Fri Dec 11 16:57:33 CST 2015
sdk.dir=/var/lib/jenkins/tools/android-sdk複製代碼
##請使用插件Jenkins
提供各類強大的插件好比:
Gradle plugin
:能夠配置管理本地的gradle。Git Parameter Plug-In
:能夠幫助在Jenkins中更好的管理git。Android Emulator Plugin
:能夠管理Android sdk,也能夠幫助集成Android項目。Jenkins
的有各類強大的插件,若是某個配置或者某個工具不知道在Jenkins
中使用,能夠嘗試找下它的插件。