为何会出现在Android工作室项目二期build.gradle文件? [英] Why are there two build.gradle files in an Android Studio project?

查看:110
本文介绍了为何会出现在Android工作室项目二期build.gradle文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在已经进口的Eclipse项目到Android的工作室,我看到两个 build.gradle 文件:

After having imported an Eclipse project into Android Studio, I see two build.gradle files:

1 - <PROJECT_ROOT>\build.gradle
2 - <PROJECT_ROOT>\app\build.gradle

第一个版本更短,第二个版本包含定义 compileSdkVersion 等。

什么背后有两个单独的文件的目的是什么?是否有单独的构建任务?

What is the purpose behind having two separate files? Are there separate build tasks?

推荐答案

&LT; PROJECT_ROOT&GT; \程序\ build.gradle 是具体的应用模块

&LT; PROJECT_ROOT&GT; \ build.gradle 顶级构建文件在这里你可以对所有子添加常用的配置选项-projects /模块。

<PROJECT_ROOT>\build.gradle is a "Top-level build file" where you can add configuration options common to all sub-projects/modules.

如果您使用其它模块项目,为当地的图书馆,你还会有一个 build.gradle 文件: &LT; PROJECT_ROOT&GT; \模块\ build.gradle

If you use another module in your project, as a local library you would have another build.gradle file: <PROJECT_ROOT>\module\build.gradle

有关示例在你的顶层文件,您可以指定这些共同的属性:

For example in your top level file you can specify these common properties:

buildscript {
    repositories {
        mavenCentral()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:1.3.0'
    }
}

ext {
    compileSdkVersion = 23
    buildToolsVersion = "23.0.1"
}

在你的应用程序\ build.gradle

apply plugin: 'com.android.application'

repositories {
    mavenCentral()
}

android {
    compileSdkVersion rootProject.ext.compileSdkVersion
    buildToolsVersion rootProject.ext.buildToolsVersion
}

这篇关于为何会出现在Android工作室项目二期build.gradle文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆