1、下載gradle
shell指令:
~ builder$ brew install gradle
檢查是否安裝完畢:
~ builder$ gradle -version
------------------------------------------------------------
Gradle 4.2.1
------------------------------------------------------------
Build time: 2017-10-02 15:36:21 UTC
Revision: a88ebd6be7840c2e59ae4782eb0f27fbe3405ddf
Groovy: 2.4.12
Ant: Apache Ant(TM) version 1.9.6 compiled on June 29 2015
JVM: 1.8.0_131 (Oracle Corporation 25.131-b11)
OS: Mac OS X 10.12.6 x86_64
2似谁、原生項(xiàng)目修改build.gradle配置
打開app目錄下的build.gradle时捌,并加上一段編譯代碼
apply plugin: 'com.android.application'
apply plugin: 'android-apt'
android {
.........// 有很多默認(rèn)配置信息
//由于國(guó)內(nèi)網(wǎng)絡(luò)情況影響,默認(rèn)gradle地址無法訪問岭埠,
//編譯會(huì)報(bào)錯(cuò),加上此行忽略報(bào)錯(cuò)依舊執(zhí)行build
lintOptions{
abortOnError false
}
}
3蔚鸥、原生項(xiàng)目修改local.properties配置
## 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.
#Thu Jul 27 09:49:07 CST 2017
# WIN系統(tǒng)下枫攀,機(jī)器編譯環(huán)境地址
#ndk.dir=E\:\\sdk\\ndk-bundle
#sdk.dir=E\:\\sdk
# MAC OS下,機(jī)器編譯環(huán)境地址
ndk.dir=/Users/builder/Library/Android/sdk/ndk-bundle
sdk.dir=/Users/builder/Library/Android/sdk
4株茶、jenkins shell命令配置
說明:svn配置在此不做贅述
下圖為shell命令配置
0001.png
執(zhí)行構(gòu)建后的效果總共分為三個(gè)步驟:下載依賴->清理項(xiàng)目->編譯項(xiàng)目成APK
Started by user APPbuild
Building in workspace /Users/builder/.jenkins/workspace/AndroidDemo
Updating svn://172.16.1.202/zgcsx/android/Master at revision '2017-10-25T15:31:05.447 +0800'
Using sole credentials ke_li/****** in realm ‘<svn://172.16.1.202:3690> 545e6826-7b7a-4598-b980-8796c9348690’
U .gitignore
D local.properties
A local.properties
At revision 5097
Using sole credentials ke_li/****** in realm ‘<svn://172.16.1.202:3690> 545e6826-7b7a-4598-b980-8796c9348690’
[AndroidDemo] $ /bin/sh -xe /var/folders/s3/rkpsdb0x223c37qsfp9wwzhw0000gn/T/jenkins8814663042433137266.sh
+ gradle init
Starting a Gradle Daemon (subsequent builds will be faster)
File /Users/builder/.android/repositories.cfg could not be loaded.
Checking the license for package Android SDK Build-Tools 25 in /Users/builder/Library/Android/sdk/licenses
License for package Android SDK Build-Tools 25 accepted.
Preparing "Install Android SDK Build-Tools 25 (revision: 25.0.0)".
"Install Android SDK Build-Tools 25 (revision: 25.0.0)" ready.
Finishing "Install Android SDK Build-Tools 25 (revision: 25.0.0)"
Installing Android SDK Build-Tools 25 in /Users/builder/Library/Android/sdk/build-tools/25.0.0
"Install Android SDK Build-Tools 25 (revision: 25.0.0)" complete.
"Install Android SDK Build-Tools 25 (revision: 25.0.0)" finished.
Download ........// 這里會(huì)下很多依賴包
:init
The build file 'build.gradle' already exists. Skipping build initialization.
:init SKIPPED
BUILD SUCCESSFUL in 2m 8s
+ gradle clean
The setTestClassesDir(File) method has been deprecated and is scheduled to be removed in Gradle 5.0. Please use the setTestClassesDirs(FileCollection) method instead.
The getTestClassesDir() method has been deprecated and is scheduled to be removed in Gradle 5.0. Please use the getTestClassesDirs() method instead.
The ConfigurableReport.setDestination(Object) method has been deprecated and is scheduled to be removed in Gradle 5.0. Please use the method ConfigurableReport.setDestination(File) instead.
:clean
:app:clean
BUILD SUCCESSFUL in 1s
2 actionable tasks: 2 executed
+ gradle build
The setTestClassesDir(File) method has been deprecated and is scheduled to be removed in Gradle 5.0. Please use the setTestClassesDirs(FileCollection) method instead.
The getTestClassesDir() method has been deprecated and is scheduled to be removed in Gradle 5.0. Please use the getTestClassesDirs() method instead.
The ConfigurableReport.setDestination(Object) method has been deprecated and is scheduled to be removed in Gradle 5.0. Please use the method ConfigurableReport.setDestination(File) instead.
...... // 這里有很多編譯信息来涨,包括沒有編譯通過的信息
:app:test UP-TO-DATE
:app:check
:app:build
BUILD SUCCESSFUL in 1m 24s
68 actionable tasks: 68 executed
Finished: SUCCESS
3、編譯注意:
請(qǐng)?jiān)趃radle中配置好打包的key與alias的值启盛,否則上面的打包方式打出來的包無法安裝蹦掐!