Android Studio的project中两个build.gradle配置的区别
发布时间 2023-08-09 15:14:56作者: herry507
classpath的作用:
buildscript itself needs something to run, use classpath
complie的作用:
your project needs something to run, use compile
在Project中的gradle的dependencies 指添加依赖是使用classpath的,classpath一般是添加buildscript本身需要运行的东西,
那么buildscript是用来什么呢?buildScript是用来加载gradle脚本自身需要使用的资源,可以声明的资源包括依赖项、第三方插件、maven仓库地址等。
在app中的gradle中dependencies 中添加的使应用程序所需要的依赖包,也就是项目运行所需要的东西。
build.gradle(项目:我的应用程序)
顶级构建文件,你可以在其中添加所有子项目/模块通用的配置选项。
每个项目都包含一个顶级 Gradle 文件。它通常包含所有modules
. 无论这个顶级 Gradle gile 中包含什么,它都会影响所有模块。
例子:
build.gradle(模块:应用程序)
特定模块的构建文件(在其中添加依赖项、签名配置、构建类型、风味等)
所有模块都有一个特定的 Gradle 文件。无论这个gradle文件中包含什么,它只会影响包含的模块。
例子:
apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.hrskrs.gesturefun"
minSdkVersion 10
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
buildTypes {
release {
zipAlignEnabled true
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
debuggable true
zipAlignEnabled true
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(':gesture-fun')
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
compile 'com.jakewharton:butterknife:7.0.1'
}