AndroidAndroid技术知识手机移动程序开发

Android build.gradle的基本配置参数详解

2017-08-15  本文已影响64人  _那个人

本篇为自己的对一个小Demo的build.gradle配置的一些看法,望大神们检查纠正!

applyplugin:'com.android.application'//安卓应用插件,如果我们的项目时作为module的话要引入 applyplugin:'com.android.liarbry'

android {

compileSdkVersion 25        //编译SDK的版本.

buildToolsVersion "25.0.2"   //build  tools的版本,可以在我们的SDK的目录下的build tools的目录下查看.

lintOptions{                        //项目在编译的时候会检测lint,有任何错误提示会停止build.

abortOnError = false          //这样设置是即使报错也不会停止打包.

}

packagingOptions {        //暂未了解 读者清楚的话请留言.

exclude'META-INF/LICENSE'

exclude'META-INF/NOTICE'

}

defaultConfig {         //默认配置.

applicationId  "com.wang.rxjava2"  //这个是标识app进程的id,和AndroidManifest里面的包名各司其职,AndroidManifest里面的包名是指定R文件和                                                             引用资源.如果这里不设置的话默认就是AndroidManifest里面的包名.

minSdkVersion  15                         //默认支持的最小SDK的版本.

targetSdkVersion  25                    //目标SDK的版本,如果跟当前使用的SDK版本一致的话Android平台就不进行兼容性检测,提高效率.系统将为你的                                                        应用开启一些最新的功能和特性。假如targetSdkVersion 为23或者更高,那么在Android6.0中运行这个应用时                                                          会开启新的功能和特性;但是设置成了22的话,只能说明你的应用程序在Android5.1系统上做过了充分的测                                                              试,Android6.0的新功能就不会启用了

versionCode  1                              //APP版本更新了多少次默认为1 次,记得每次迭代的时候都要把该值改变.

versionName   "1.0"                        //版本的名称,将显示在应用商场上面.

testInstrumentationRunner"android.support.test.runner.AndroidJUnitRunner"

proguardFiles getDefaultProguardFile('proguard-android.txt'),'proguard-rules.pro'  //混淆时使用的文件路径

}

buildTypes {

release {//release版本配置

zipAlignEnabled   true       //是否支持压缩文件

minifyEnabledf   alse            //是否进行混淆

shrinkResources  true         //是否移出无用的resurce资源

debuggablefalse                 //是否开启调试

proguardFiles getDefaultProguardFile('proguard-android.txt'),'proguard-rules.pro'

}

}

compileOptions{          //对Java版本的一些配置

sourceCompatibility org.gradle.api.JavaVersion.VERSION_1_8

targetCompatibility org.gradle.api.JavaVersion.VERSION_1_8

 }

}

dependencies {    //依赖的资源库

compile fileTree(include: ['*.jar'],dir:'libs')            //本地文件的依赖 ,把项目中的libs文件夹下的所有.jar的文件都加载到项目的构建中去

compile project(':OneSDK')                                 //依赖本地的Module

androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {

excludegroup:'com.android.support',module:'support-annotations'

})                                                                            //检查本地是否已经缓存了远程的库,是的话就不缓存,不是的话就缓存

compile'com.android.support:appcompat-v7:25.3.1'

testCompile'junit:junit:4.12'                                       //单元测试

compile'io.reactivex.rxjava2:rxjava:2.1.1'                 //其他的依赖

}

上一篇 下一篇

猜你喜欢

热点阅读