Android官网:Configuring Gradle Builds英译

配置Gradle编译

  • 编译配置基础内容
    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'])
}
  1. apply plugin:’com.android.application’
    将Gradle的Android插件用到了这个build中:添加了Android指定的构建任务到这个顶级的构建任务中,并且使得android {…}元素对于指定的Android元素是可用的

  2. 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.
    点击同步构建配置

  3. 依赖的声明
    在这个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:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值