Я начал проект в Android Studio, с IntelliJ.
Проект включает в себя два файла, называемых build.gradle
. Один находится под app
папки, а один находится под основной папкой, которая является именем моего проекта, например MyProject
.
Зачем нужны два? В чем разница между двумя build.gradle
s?
Проект Android Studio состоит из модулей, библиотек, файлов манифеста и файлов сборки Gradle.
Каждый проект содержит один файл сборки верхнего уровня Gradle. Этот файл называется build.gradle и может быть найден в каталоге верхнего уровня.
Этот файл обычно содержит общую конфигурацию для всех модулей, общих функций.
Пример:
//gradle-plugin for android buildscript { repositories { mavenCentral() //or jcenter() } dependencies { classpath 'com.android.tools.build:gradle:0.12.2' } } // common variables ext { compileSdkVersion = 19 buildToolsVersion = "20.0.0" } // a custom function def isReleaseBuild() { return version.contains("SNAPSHOT") == false } //common config for all projects allprojects { version = VERSION_NAME repositories { mavenCentral() } }
Все модули имеют определенный файл build.gradle
. Этот файл содержит всю информацию об этом модуле (поскольку проект может содержать больше модулей), как config, build tyoes, info для подписания ваших apk, зависимостей ….
Пример:
apply plugin: 'com.android.application' android { //These lines use the constants declared in top file compileSdkVersion rootProject.ext.compileSdkVersion buildToolsVersion rootProject.ext.buildToolsVersion defaultConfig { minSdkVersion 14 targetSdkVersion 19 versionName project.VERSION_NAME //it uses a property declared in gradle.properties versionCode Integer.parseInt(project.VERSION_CODE) } // Info about signing signingConfigs { release } // Info about your build types buildTypes { if (isReleaseBuild()) { release { signingConfig signingConfigs.release } } debug { applicationIdSuffix ".debug" versionNameSuffix "-debug" } } // lint configuration lintOptions { abortOnError false } } //Declare your dependencies dependencies { //Local library compile project(':Mylibrary') // Support Libraries compile 'com.android.support:support-v4:20.0.0' // Picasso compile 'com.squareup.picasso:picasso:2.3.4' }
Вы можете найти более подробную информацию здесь: http://developer.android.com/sdk/installing/studio-build.html