Android Studio中Module下的gradle文件的基本配置
来源:互联网 发布:网络语右友是什么意思 编辑:程序博客网 时间:2024/05/22 00:13
欢迎加入交流群:微信群(AndroidRunner )、QQ群(314896948)
欢迎关注微信公众号:AndroidRunner
在项目的module目录下的gradle文件主要包含三个节点,分别是apply、android和dependencies,下面就将这三个节点分别做一个介绍。
1.apply节点
apply所标识的用以区分了application以及library。这个节点的作用就是用来区分当前module是可以作为应用程序还是作为一个应用程序的支持库module。
application module使用如下:
applyplugin:'com.android.application'
library使用如下:
apply plugin: 'com.android.library'
2.android节点
packagingOptions
packagingOptions { pom.properties' exclude 'project.properties' exclude 'META-INF/LICENSE.txt' exclude 'META-INF/LICENSE' exclude 'META-INF/NOTICE.txt' exclude 'META-INF/NOTICE' exclude 'META-INF/DEPENDENCIES.txt' exclude 'META-INF/DEPENDENCIES' }
我们在开发过程当中可能会遇到这样的问题,导入了很多的三方库或者框架,在项目编译的时候会报重复文件错误,如下图
解决这个错误的方法就可以在packagingOptions中加入以下两句:exclude 'META-INF/maven/com.squareup.okio/okio/pom.xml'exclude 'META-INF/maven/com.squareup.okio/okio/pom.properties'
lintOptions
lintOptions { disable 'MissingTranslation' abortOnError false ignoreWarnings true }
其中
disable 'MissingTranslation'
是在lint检查的时候禁用翻译缺少检查,如果你的项目不考虑国际化可以加上,如果需要国际化就去掉该行即可。abortOnError false
设置在lint检查时如果出现error是否需要中断,如果对lint检查要求不高可以设置为false,关心lint检查的话设置true即可。ignoreWarnings true
设置是否忽略警告,在lint检查时会对一些代码进行警告比如有用了过时API的注解地方,一般可以设置为true,忽略掉警告。lintOptions还有其他一些控制开关,具体可以点进lintOptions源码查看。signingConfigs
signingConfigs { debug { keyAlias 'android' keyPassword 'android' storeFile file('E:/debug.jks') storePassword 'android' } release { keyAlias 'psw' keyPassword 'psw' storeFile file('keystore addresss') storePassword 'psw' } }
signingConfigs是项目module的签名配置信息,主要包括调试版和发布版,考虑隐私信息可以仅使用debug即可,release在导出包使用手动添加。几个字段含义应该开发者都比较清楚了,这里不做介绍。
compileSdkVersion
compileSdkVersion 23
编译SDk的版本号,改版本号决定使用的SDK对应的android源码,android源码随着版本的不断更新,各个版本间也有着一定的区别,这里所填写的版本号关系到具体代码的一些API的使用,可以根据当前APP的版本兼容要求做相应的兼容。
buildToolsVersion
buildToolsVersion "23.0.2"
使用的编译工具版本号指定,对于应编译版本号即可。
defaultConfig
defaultConfig { applicationId "com.xxx"//app的唯一标识符,一般使用包名 minSdkVersion 14 //app要求最低的SDK版本号 对于应android可使用的最低系统版本 targetSdkVersion 23 //目标版本SDK版本号 versionCode 1 // app版本号 versionName "1.0.0" // app版本名称 // 多渠道打包默认渠道(以umeng为例) manifestPlaceholders = [UMENG_CHANNEL_VALUE: "GF"] }
defaultConfig里面可以设置app的一些相关默认配置信息,包括应用的id,可使用最低版本,版本号,版本名称等。
buildTypes
buildTypes { debug { minifyEnabled false zipAlignEnabled false shrinkResources false } release { minifyEnabled true zipAlignEnabled true shrinkResources true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' }}
buildTypes设置编译对应的版本时所需的一些配置设置,可以针对调试版和发布版进行不同的设置是否需要混淆、是否需要压缩、是否需要删减无用资源等。
sourceSets
sourceSets.main { jniLibs.srcDir 'libs'}
sourceSets用来设置项目对应文件资源的路径位置,比如习惯平常的把jni文件so包存放在libs目录下即可设置
jniLibs.srcDir 'libs'
,也可以设置其他文件目录,包括源码,资源,jar包等等。productFlavors
productFlavors { GF {} wandoujia {} //... add more } productFlavors.all { flavor -> flavor.manifestPlaceholders = [UMENG_CHANNEL_VALUE: name] }
productFlavors提供了多渠道打包的渠道设置,成列了可生产的取到列表,productFlavors.all通过遍历productFlavors中的所有条目对应替换AndroidManifest.xml下面meta节点key为UMENG_CHANNEL_VALUE的value,从而生成对应渠道的apk包
3.dependencies
dependencies下面是项目的依赖第三方支持库存放,包括libs目录及目录树下子目录所有的jar包,以及按照jcenter仓库库命名的的三方支持库。样例如下:
dependencies { compile fileTree(include: ['*.jar'], dir: 'libs') compile 'com.android.support:appcompat-v7:23.3.0' compile 'com.android.support:design:23.3.0' compile 'com.squareup.picasso:picasso:2.5.2' //picasso compile 'com.squareup.okio:okio:1.6.0' //okio compile 'com.squareup:otto:1.3.8' //otto compile 'com.alibaba:fastjson:1.2.7' //fastjson}
下面给出一个完整的gradle基本配置
apply plugin: 'com.android.application'android { packagingOptions { exclude 'project.properties' exclude 'META-INF/LICENSE.txt' exclude 'META-INF/LICENSE' exclude 'META-INF/NOTICE.txt' exclude 'META-INF/NOTICE' exclude 'META-INF/DEPENDENCIES.txt' exclude 'META-INF/DEPENDENCIES' } lintOptions { disable 'MissingTranslation' abortOnError false ignoreWarnings true } signingConfigs { debug { keyAlias 'android' keyPassword 'android' storeFile file('E:/debug.jks') storePassword 'android' } release { keyAlias 'psw' keyPassword 'psw' storeFile file('keystore addresss') storePassword 'psw' } } compileSdkVersion 23 buildToolsVersion "23.0.2" defaultConfig { applicationId "com.xxx"//app的唯一标识符,一般使用包名 minSdkVersion 14 //app要求最低的SDK版本号 对于应android可使用的最低系统版本 targetSdkVersion 23 //目标版本SDK版本号 versionCode 1 // app版本号 versionName "1.0.0" // app版本名称 // 多渠道打包默认渠道(以umeng为例) manifestPlaceholders = [UMENG_CHANNEL_VALUE: "GF"] } buildTypes { debug { minifyEnabled false zipAlignEnabled false shrinkResources false } release { minifyEnabled true zipAlignEnabled true shrinkResources true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } sourceSets.main { jniLibs.srcDir 'libs' } productFlavors { GF {} wandoujia {} //... add more } productFlavors.all { flavor -> flavor.manifestPlaceholders = [UMENG_CHANNEL_VALUE: name] }}dependencies { compile fileTree(include: ['*.jar'], dir: 'libs') compile 'com.android.support:appcompat-v7:23.3.0' compile 'com.android.support:design:23.3.0' compile 'com.squareup.picasso:picasso:2.5.2' //picasso compile 'com.squareup.okio:okio:1.6.0' //okio compile 'com.squareup:otto:1.3.8' //otto compile 'com.alibaba:fastjson:1.2.7' //fastjson}
- Android Studio中Module下的gradle文件的基本配置
- Android Studio中module配置好的bulid.gradle和混淆proguard-rules.pro
- Android Studio中Module的build.gradle详解
- Android Studio中Module的build.gradle详解
- Android Studio中Module的build.gradle详解
- Gradle配置非Module文件下的子项目资源
- Android Studio module + gradle的巧妙运用
- Android Studio中Gradle的配置
- Android Studio删除project下的module后弹出:Gradle failed: already disposed module:XX 问题:
- Android Studio中manifest文件中的package包名和module中的build.gradle中applicationId的区别
- Android studio的gradle配置
- Android studio的gradle配置
- Android开发工具:Android Studio中Gradle的配置
- Android Studio的gradle下配置ndk,jni
- mac下Android studio配置gradle的路径
- mac os x下配置Android Studio 的 gradle
- Android Studio gradle的基本用法
- Android Studio 中Gradle配置debug使用release的签名
- C/C++程序员应聘常见面试题深入剖析
- yii 各大框架文件上传(文件,视频,音乐)
- Java学习提要——接口进阶
- MACOS brew 安装与卸载
- KODI make
- Android Studio中Module下的gradle文件的基本配置
- 3D图形学编程基础-基于Direct3D11-学习记录(四)混合的使用
- 字体和文本输出:CFont字体类
- 分类,回归,标注
- 几款主流数据库的详细比较
- 学习笔记之——内存溢出OOM问题
- keepalived安装与配置
- php 连接数据库存储数据
- Android开发笔记(一百二十三)下拉刷新布局SwipeRefreshLayout