我正在尝试让我现有的 Android 项目与 gradle 和 IntelliJ 12 一起工作。
以前我让它与 maven 一起工作,但它似乎不像 gradle 那样灵活,而且我认为我知道我需要更少的子文件夹。
我的 Android 项目分为干净的 java 库 (:core) 和实际的应用程序 (:android)。这两个项目都在我的主项目文件夹中。
~-+MainProject
|--+core
| L--build.gradle
|--+android
| L--build.gradle
|--build.gradle
L--settings.gradle
我认为让 gradle 工作的理想解决方案是将 (:core) 和 (:android) 项目视为嵌套项目,这意味着我可以简单地在 MainProject 源文件夹中使用我的 cmd 来启动 gradle 任务。
但是我想出了不同的问题:
目录正确设置为源/测试目录
这是 *.gradle 配置
主要项目:
-- settings.gradle
include ':core', ':android'
-- build.gradle
buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.6.+'
}
}
subprojects {
repositories {
mavenLocal()
maven { url "http://repo.maven.apache.org/maven2" }
}
}
:核
-- build.gradle
apply plugin: 'java'
dependencies {
testCompile 'junit:junit:4.11'
testCompile 'org.mockito:mockito-core:1.9.5'
}
:安卓
apply plugin: 'android'
repositories {
mavenCentral()
}
dependencies {
compile project(":core")
compile 'com.google.android:android:4.1.1.4'
instrumentTestCompile 'junit:junit:4.11'
instrumentTestCompile 'org.mockito:mockito-core:1.9.5'
instrumentTestCompile 'com.google.dexmaker:dexmaker:1.0'
instrumentTestCompile 'com.google.dexmaker:dexmaker-mockito:1.0'
instrumentTestCompile 'com.jayway.android.robotium:robotium-solo:3.6'
}
/* ... androidSettings
我希望有人可以帮助我
MFG多纳塔尔
最佳答案
好的,所以您的想法是正确的,但是您仍然需要进行一些更改。
您的根 build.gradle
文件应如下所示:
subprojects {
repositories {
mavenCentral()
}
}
mavenLocal()
如果您使用的是本地安装的存储库。大多数人不这样做,并且您的项目中没有任何内容表明您需要一个。 mavenCentral()
可用于替换您正在使用的 Maven URL。 build.gradle
. 您的
settings.gradle
和您的 build.gradle
对于核心项目都不错。您的
build.gradle
但是,对于 android 项目,需要进行一些更改:buildscript {
repositories {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:0.6.+'
}
}
apply plugin: 'android'
dependencies {
compile project(":core")
instrumentTestCompile 'com.jayway.android.robotium:robotium-solo:3.6'
}
compile 'com.google.android:android:4.1.1.4'
. junit
.它由 SDK 提供,因此我们将使用它。需要注意的一件事是 SDK 仅包含 JUnit 3。mockito
和 dexmaker
除非我们实际将其用于 android 测试。如果它只用于java库上的测试,我们这里不需要它。 回答您的问题:
最后一点。 Intellij 12 无法处理 Gradle 多项目构建。为此,您需要切换到 Android Studio 或 Intellij 13。
关于intellij-idea - IntelliJ、Android 和 Gradle,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20133414/