記錄android Studio Gradle的一些常用的基本配置
//去除對.9圖片的檢查
lintOptions{
checkReleaseBuilds false
abortOnError false
}
//關閉Android Studio的PNG合法性檢查的
aaptOptions.cruncherEnabled = false
aaptOptions.useNewCruncher = false
//簽名配置
signingConfigs {
TSB_IntegrationForTongHua { //簽名配置的引用處
keyAlias 'tecsun' //簽名文件的別名
keyPassword 'tonghua' //簽名文件的別名
storeFile file('../app/key/tecsun_tonghua.jks') //簽名文件的存儲路徑
storePassword 'tonghua' //簽名文件的密碼
}
}
buildTypes {
debug { //開發階段
minifyEnabled false //打包是否混淆,false表示否
buildConfigField "boolean","LOG_CALLS",
"false"
}
release { //正式發布
buildConfigField "boolean","LOG_CALLS",
"true"
minifyEnabled true //打包是否混淆,true表示是
debuggable false //是否支持調試
shrinkResources true //是否刪除無用的文件
zipAlignEnabled true //是否開啟zip壓縮
//混淆文件的配置
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
//簽名配置的引用
signingConfig signingConfigs.TSB_IntegrationForTongHua
}
}
使用了上一個buildTypes中的buildConfigField 配置,在各自封裝的LogUtils中需要做如下的配置,這樣每次打正式包的時候就不用手動去關閉log的輸出
public class LogUtils {
public static final boolean DEGBULE = BuildConfig.LOG_CALLS;
}
//指定libs路徑
repositories {
flatDir {
dirs 'libs'
}
}
splits {//配置so
abi {
enable true
reset()
include 'armeabi'//僅armeabi保留
universalApk false//是否要打包一個通用的apk
}
}
//工程從Eclipse遷過來的代碼的配置
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'/指定AndroidManifest文件
java.srcDirs = ['src'] //指定source目錄
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res'] //指定資源目錄
assets.srcDirs = ['assets'] //指定assets庫目錄
}
// Move the tests to tests/java, tests/res, etc...
instrumentTest.setRoot('tests')
// Move the build types to build-types/<type>
// For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
// This moves them out of them default location under src/<type>/... which would
// conflict with src/ being used by the main source set.
// Adding new build types or product flavors should be accompanied
// by a similar customization.
debug.setRoot('build-types/debug') //指定debug模式的路徑
release.setRoot('build-types/release') //指定release模式的路徑
}
dependencies {
//導入文件的類型
compile fileTree(include: ['*.jar'], dir: 'libs')
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
//導入單元測試
testCompile 'junit:junit:4.12'
//導入jar包
compile files('libs/gson-2.5.jar')
//導入aar包
compile(name: 'logger-1.15', ext: 'aar')
//導入遠程庫
compile 'com.android.support:appcompat-v7:25.+'
//導入本地module依賴庫
compile project(':RecyclerViewLibrary')
}