摇篮打造为集的Android项目(包括库) [英] Gradle build for set of Android projects (including libraries)
问题描述
我有2 5款Android模块(安卓库项目)的Android应用程序。共有7 Eclipse项目。我想启用摇篮打造他们。我加了 build.gradle
在根文件夹,并列入 settings.gradle
I have 2 Android apps with 5 Android modules (Android library project). Total 7 Eclipse projects. I want to enable Gradle build for them. I added build.gradle
in the root folder and listed all project in settings.gradle
include ':app1'
include ':app2'
...
不过,我发现,我需要复制粘贴以下部分的每一个7项目
However I discovered that I need to copy-paste section below in every one of 7 project
android {
compileSdkVersion 19
buildToolsVersion "19.0.3"
defaultConfig {
minSdkVersion 1
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
... // and so on like source folders configuration
}
原因:当我添加应用插件:'机器人'
里面的根 build.gradle
(见<一href="http://stackoverflow.com/questions/23864068/could-not-find-method-android-in-root-of-multimodule-project">Could没有找到的多模块项目根法的Android()),
那么我不能应用插件:机器人库
图书馆项目(见<一href="http://stackoverflow.com/questions/23864292/minimal-gradle-configuration-for-android-library-in-multimodule-project">Minimal摇篮配置的多模块项目的Android库)
Reason: when I add apply plugin: 'android'
inside root build.gradle
(see Could not find method android() in root of multimodule project),
then I can't apply plugin: 'android-library'
for libraries projects (see Minimal Gradle configuration for Android library in multimodule project)
但它是什么,我想避免,具有不同版本的Android,并在不同的地方指定的Android工具。
But it is what I want to avoid, having different version of Android and Android tools specified in different places.
如何运行如下此配置中获得尽可能多的东西尽可能在一个 build.gradle
配置文件。
How can I minify this configuration to have as many things as possible in one build.gradle
config file.
推荐答案
您可以使用根你的 build.gradle
,也可以在<$ C定义一些值$ C> gradle.properties 的根文件夹来实现自己的范围。
You can use your build.gradle
in root, or you can define some values in gradle.properties
in root folder to achieve your scope.
例如:
根/ build.gradle
:
ext {
compileSdkVersion = 19
buildToolsVersion = "19.0.3"
}
模块/ build.gradle
:
android {
compileSdkVersion rootProject.ext.compileSdkVersion
buildToolsVersion rootProject.ext.buildToolsVersion
}
或使用性质
根/ gradle.properties
:
VERSION_NAME=1.0.1
VERSION_CODE=11
模块/ build.gradle
:
android {
defaultConfig {
versionName project.VERSION_NAME
versionCode Integer.parseInt(project.VERSION_CODE)
}
这篇关于摇篮打造为集的Android项目(包括库)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!