gradle 安裝
安裝的前提是配置完成JDK環境:Linux下jdk的配置
1、在官網下載下傳
2、解壓安裝包到目錄
/root/A
3、打開環境檔案
sudo vim /etc/profile
4、寫入環境變量:
export GRADLE_HOME=/root/A/gradle-2.0
export PATH=$GRADLE_HOME/bin:$PATH
5、環境變量生效
source /etc/profile
6、檢查結果
gradle -v
如果Gradle環境配置成功,此時會有類似如下内容的版本資訊出現:
-----------------------------------------------------------
Gradle 2.14.1
------------------------------------------------------------
Build time: 2016-07-18 06:38:37 UTC
Revision: d9e2113d9fb05a5caabba61798bdb8dfdca83719
Groovy: 2.4.4
Ant: Apache Ant(TM) version 1.9.6 compiled on June 29 2015
JVM: 1.8.0_112 (Oracle Corporation 25.112-b15)
OS: Linux 4.4.0-3-deepin-amd64 amd64
gradle 配置
我們需要配置的三個檔案:build.gradle:編譯規則 gradle.properties此檔案用于配置本地的SDK和NDK所在的目錄, SDK目錄對應sdk.dir, NDK目錄對應ndk.dir 如果不需要ndk支援,可直接使用"//"注釋掉ndk.dir行 *注意路徑中的':'也需要使用轉義字元''來修飾為':' local.properties此檔案用于配置全局參數,keystore目錄也在此配置
build.gradle的配置:
apply plugin: 'com.android.application'//說明module的類型,com.android.application為程式,com.android.library為庫
android {
compileSdkVersion //編譯的SDK版本
buildToolsVersion "22.0.1"//編譯的Tools版本
defaultConfig {//預設配置
applicationId "com.nd.famlink"//應用程式的包名
minSdkVersion //支援的最低版本
targetSdkVersion //支援的目标版本
versionCode //版本号
versionName "3.0.1"//版本名
}
sourceSets {//目錄指向配置
main {
manifest.srcFile 'AndroidManifest.xml'//指定AndroidManifest檔案
java.srcDirs = ['src']//指定source目錄
resources.srcDirs = ['src']//指定source目錄
aidl.srcDirs = ['src']//指定source目錄
renderscript.srcDirs = ['src']//指定source目錄
res.srcDirs = ['res']//指定資源目錄
assets.srcDirs = ['assets']//指定assets目錄
jniLibs.srcDirs = ['libs']//指定lib庫目錄
}
debug.setRoot('build-types/debug')//指定debug模式的路徑
release.setRoot('build-types/release')//指定release模式的路徑
}
signingConfigs {//簽名配置
release {//釋出版簽名配置
storeFile file("fk.keystore")//密鑰檔案路徑
storePassword "123"//密鑰檔案密碼
keyAlias "fk"//key别名
keyPassword "123"//key密碼
}
debug {//debug版簽名配置
storeFile file("fk.keystore")
storePassword "123"
keyAlias "fk"
keyPassword "123"
}
}
buildTypes {//build類型
release {//釋出
minifyEnabled true//混淆開啟
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-project.txt'//指定混淆規則檔案
signingConfig signingConfigs.release//設定簽名資訊
}
debug {//調試
signingConfig signingConfigs.release
}
}
packagingOptions {
exclude 'META-INF/ASL2.0'
exclude 'META-INF/LICENSE'
exclude 'META-INF/NOTICE'
exclude 'META-INF/MANIFEST.MF'
}
lintOptions {
abortOnError false//lint時候終止錯誤上報,防止編譯的時候莫名的失敗
}
}
dependencies {
compile fileTree(dir: 'libs', exclude: ['android-support*.jar'], include: ['*.jar']) //編譯lib目錄下的.jar檔案
compile project(':Easylink')//編譯附加的項目
compile project(':ImageLibrary')
compile project(':ImageResLibrary')
compile project(':Ofdmtransport')
compile project(':PullToRefreshLibrary')
compile project(':RecorderLibrary')
compile project(':WebSocket')
compile project(':WidgetLibrary')
compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.3'//編譯來自Jcenter的第三方開源庫
}
gradle.properties的配置:
# Project-wide Gradle settings.
#
# IDE (e.g. Android Studio) users:
# Gradle settings configured through the IDE *will override*
# any settings specified in this file.
#
# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html
#
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
# Default value: -Xmx10248m -XX:MaxPermSize=256m
# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
#
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
KEYSTORE_DEBUG_PATH=/root/Download/keystore/keystore/platform.keystore
KEYSTORE_DEBUG_PATH_WINDOWS=D\:\\keystore\\platform.keystore//windows下的路徑
KEYSTORE_DEBUG_STORE_PASSWORD=android
KEYSTORE_DEBUG_KEY_ALIAS=androidplatformkey
KEYSTORE_DEBUG_KEY_PASSWORD=android
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.
# Wed Jun 15 11:01:52 CST 2016
sdk.dir=/root/Download/android-sdk
ndk.dir =/root/Download/android-ndk
配置好着兩個檔案之後接下來就可以去使用Gradel了
Gradel的使用:
檢視目前工程支援的操作任務
gradle tasks
清理工程
gradle clean
編譯項目debug版本 ,并輸出到output目錄
gradle assembleDebug
編譯項目release版本 ,并輸出到output目錄
gradle assembleRelease
代碼檢查及測試
gradle check
編譯項目并執行檢查及測試,即assemble + check
gradle build