Android官网:Configuring Gradle Builds英译
2015-12-29 14:52
483 查看
配置Gradle编译
编译配置基础内容
Android studio 的一个Project包含了一个build文件,另外每个module都包含了一个build文件。这些文件的文件名为build.gradle。它们原本是空白的文本,用了Groovy语法来配置Android提供的Gradle插件提供的元素。在大多数情况下,你只需要配置module里面的那个gradle文件,例如,BuildSystemGradle项目中的build文件,如下:
apply plugin:’com.android.application’
将Gradle的Android插件用到了这个build中:添加了Android指定的构建任务到这个顶级的构建任务中,并且使得android {…}元素对于指定的Android元素是可用的
android {…}
配置了所有关于Android的构建选项。
compileSdkVersion :指定了编译的目标。
buildToolsVersion :指定了使用哪个版本的构建工具。可以使用SDK Manager来安装build tools的几个不同版本。Note:建议总是使用一个修订版本比你当前的编译目标版本或者目标SDK版本高的build tools版本。
defaultConfig :从构建系统中灵活的配置了清单文件中一些主要的核心内容和记录。在defaultConfig中配置的内容应用到所有的构建变量中,除非有些构建变量再次被复写。
buildTypes :控制了怎样去构建和打包你的app,默认情况下,构建系统定义了两个构建类型:debug和release。debug构建类型包含了调试的符号,使用debug key来进行签名。release构建类型不使用默认的debug key来进行签名。在这个demo中构建文件使用proGuard来配置发布版本。
dependencies :在android元素外面。这个元素指明了module所需要的依赖。dependecies在下列部分汇中被覆盖了。Note:When you make changes to the build files in your project, Android Studio requires a project sync to import the build configuration changes. Click Sync Now on the yellow notification bar that appears for Android Studio to import the changes.
![](http://developer.android.com/images/tools/as-gradlesync.png)
依赖的声明
在这个demo中app这个module声明了三种依赖:
每种依赖在下面都有解释:
Module dependencies:
编译配置基础内容
Android studio 的一个Project包含了一个build文件,另外每个module都包含了一个build文件。这些文件的文件名为build.gradle。它们原本是空白的文本,用了Groovy语法来配置Android提供的Gradle插件提供的元素。在大多数情况下,你只需要配置module里面的那个gradle文件,例如,BuildSystemGradle项目中的build文件,如下:
apply plugin: 'com.android.application' android { compileSdkVersion 19 buildToolsVersion "19.0.0" defaultConfig { minSdkVersion 8 targetSdkVersion 19 versionCode 1 versionName "1.0" } buildTypes { release { minifyEnabled true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } } dependencies { compile project(":lib") compile 'com.android.support:appcompat-v7:19.0.1' compile fileTree(dir: 'libs', include: ['*.jar']) }
apply plugin:’com.android.application’
将Gradle的Android插件用到了这个build中:添加了Android指定的构建任务到这个顶级的构建任务中,并且使得android {…}元素对于指定的Android元素是可用的
android {…}
配置了所有关于Android的构建选项。
compileSdkVersion :指定了编译的目标。
buildToolsVersion :指定了使用哪个版本的构建工具。可以使用SDK Manager来安装build tools的几个不同版本。Note:建议总是使用一个修订版本比你当前的编译目标版本或者目标SDK版本高的build tools版本。
defaultConfig :从构建系统中灵活的配置了清单文件中一些主要的核心内容和记录。在defaultConfig中配置的内容应用到所有的构建变量中,除非有些构建变量再次被复写。
buildTypes :控制了怎样去构建和打包你的app,默认情况下,构建系统定义了两个构建类型:debug和release。debug构建类型包含了调试的符号,使用debug key来进行签名。release构建类型不使用默认的debug key来进行签名。在这个demo中构建文件使用proGuard来配置发布版本。
dependencies :在android元素外面。这个元素指明了module所需要的依赖。dependecies在下列部分汇中被覆盖了。Note:When you make changes to the build files in your project, Android Studio requires a project sync to import the build configuration changes. Click Sync Now on the yellow notification bar that appears for Android Studio to import the changes.
![](http://developer.android.com/images/tools/as-gradlesync.png)
依赖的声明
在这个demo中app这个module声明了三种依赖:
... dependencies { // Module dependency compile project(":lib") // Remote binary dependency compile 'com.android.support:appcompat-v7:19.0.1' // Local binary dependency compile fileTree(dir: 'libs', include: ['*.jar']) }
每种依赖在下面都有解释:
Module dependencies:
相关文章推荐
- 使用C++实现JNI接口需要注意的事项
- Android IPC进程间通讯机制
- Android Manifest 用法
- [转载]Activity中ConfigChanges属性的用法
- Android之获取手机上的图片和视频缩略图thumbnails
- Android之使用Http协议实现文件上传功能
- Android学习笔记(二九):嵌入浏览器
- android string.xml文件中的整型和string型代替
- i-jetty环境搭配与编译
- android之定时器AlarmManager
- android wifi 无线调试
- Android Native 绘图方法
- Android java 与 javascript互访(相互调用)的方法例子
- android 代码实现控件之间的间距
- android FragmentPagerAdapter的“标准”配置
- Android"解决"onTouch和onClick的冲突问题
- android:installLocation简析
- android searchView的关闭事件
- SourceProvider.getJniDirectories