Android中build文件夹的作用,为什么在Android Studio项目中有两个build.gradle文件?

Android Studio的项目包含顶级的build.gradle文件,用于设置所有应用模块共用的配置。每个应用模块有自己的build.gradle文件,指定特定模块的构建设置。项目级Gradle文件主要用于全局项目配置,如定义仓库和依赖。模块级Gradle文件则包含Android设置、编译SDK版本、构建类型等详细信息。
摘要由CSDN通过智能技术生成

From the official documentation:

Android Studio projects contain a top-level project Gradle build file that allows you to add the configuration options common to all application modules in the project. Each application module also has its own build.gradle file for build settings specific to that module.

8a3bdc1013f211eb31e0229b55a23491.png

Project Build File

\build.gradle or the Project Build File is for the entire project so it will be used for global project configurations.

A typical Project Build File contains the following:

buildscript which defines:

repositories and

dependencies

Gradle Plugin version

By default, the project-level Gradle file uses buildscript to define the Gradle repositories and dependencies. This allows different projects to use different Gradle versions. Supported repositories include JCenter, Maven Central, or Ivy. This example declares that the build script uses the JCenter repository and a classpath dependency artifact that contains the Android plugin for Gradle version 1.0.1.

Module Build File

\app\build.gradle or the Module Build File is for a specific module so it will be used for specific module level configs.

A Module Build File contains the following:

android settings

compileSdkVersion

buildToolsVersion

defaultConfig and productFlavors

manifest properties such as applicationId, minSdkVersion, targetSdkVersion, and test information

buildTypes

build properties such as debuggable, ProGuard enabling, debug signing, version name suffix and testinformation

dependencies

you can read the official docs here:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值