记录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')
}