[英]Why isn't Gradle picking up on my Android module dependency?
So I'm trying to create a multi-module project for the first time in IntelliJ IDEA using Gradle. 因此,我尝试使用Gradle在IntelliJ IDEA中首次创建一个多模块项目。 I've spent an hour reading the docs and various tutorials and SO-questions without being able to solve this simple case.
我花了一个小时阅读文档,各种教程和SO问题,但无法解决这个简单的问题。 My structure:
我的结构:
-Project
|-vg
|-vgcommon
vgcommon
is an Android Gradle Module, while vg
is an Android Gradle Application (technically also a module). vgcommon
是一个Android Gradle模块,而vg
是一个Android Gradle应用程序(从技术上讲也是一个模块)。
vg
depends on vgcommon
vg
取决于vgcommon
vgcommon
builds vgcommon
版本 vg
does not, as all the classes from vgcommon
are "not found". vg
没有,因为vgcommon
中的所有类都是“未找到”的。 Here are my gradle.build files and setup.gradle. 这是我的gradle.build文件和setup.gradle。 Can anyone see what I do wrong?
谁能看到我做错了吗?
settings.gradle (root level) settings.gradle (根级别)
include ':vgcommon', ':VG'
vgcommon\\build.gradle vgcommon \\ build.gradle
buildscript {
repositories {
mavenCentral()
maven { url 'http://download.crashlytics.com/maven' }
}
dependencies {
classpath 'com.android.tools.build:gradle:0.10+'
classpath 'com.crashlytics.tools.gradle:crashlytics-gradle:1+'
}
}
apply plugin: 'android'
apply plugin: 'crashlytics'
repositories {
mavenCentral()
maven { url 'http://download.crashlytics.com/maven' }
}
android {
compileSdkVersion 19
buildToolsVersion "19.1.0"
defaultConfig {
minSdkVersion 8
targetSdkVersion 19
versionCode 1
versionName "1.0"
}
buildTypes {
release {
runProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
productFlavors {
defaultFlavor {
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:19.+'
compile 'com.koushikdutta.ion:ion:1.2.4'
compile 'com.crashlytics.android:crashlytics:1+'
}
vg\\build.gradle vg \\ build.gradle
buildscript {
repositories {
mavenCentral()
maven { url 'http://download.crashlytics.com/maven' }
}
dependencies {
classpath 'com.android.tools.build:gradle:0.10+'
classpath 'com.crashlytics.tools.gradle:crashlytics-gradle:1+'
}
}
apply plugin: 'android'
apply plugin: 'crashlytics'
repositories {
mavenCentral()
maven { url 'http://download.crashlytics.com/maven' }
}
android {
compileSdkVersion 19
buildToolsVersion '19.1.0'
defaultConfig {
minSdkVersion 8
targetSdkVersion 19
}
buildTypes {
release {
runProguard false
signingConfig signingConfigs.release
debuggable false
}
}
productFlavors {
defaultFlavor {
}
}
applicationVariants.all { variant ->
variant.outputFile = file("../build/publish/app.apk")
}
}
configurations {
unitTestCompile.extendsFrom compile
unitTestRuntime.extendsFrom unitTestCompile
}
dependencies {
compile project(':vgcommon')
compile 'com.android.support:appcompat-v7:19.0.1'
compile files('libs/gcm.jar')
compile files('libs/spring-appsensor-android-1.7.1.jar')
compile files('libs/spring-util-android.jar')
compile 'com.crashlytics.android:crashlytics:1.+'
compile 'com.squareup:otto:1.3.4'
compile 'com.google.code.gson:gson:2.2.4'
compile 'com.koushikdutta.ion:ion:1.2.4'
compile 'com.mobsandgeeks:android-saripaar:1.0.2'
provided 'junit:junit:4.11'
// Next 2 Just to make IntelliJ happy:
provided 'org.mockito:mockito-all:1.9.5'
provided 'org.robolectric:robolectric:2.3'
unitTestCompile 'com.google.android:android:4+'
unitTestCompile files("$project.buildDir/classes/defaultFlavor/debug")
unitTestCompile 'junit:junit:4.11'
unitTestCompile 'org.mockito:mockito-all:1.9.5'
unitTestCompile 'org.robolectric:robolectric:2.3'
}
sourceSets {
unitTest {
java.srcDir file('src/test/java')
}
}
task unitTestDisplayResults << {
toOpen = projectDir.toString() + "/build/reports/tests/index.html"
println "Opening page: " + toOpen
("cmd /C start " + toOpen).execute()
}
task unitTest(type:Test, dependsOn: assemble) {
description = "run unit tests"
testClassesDir = project.sourceSets.unitTest.output.classesDir
classpath = project.sourceSets.unitTest.runtimeClasspath
finalizedBy unitTestDisplayResults
}
Error ouptut excerpt: 错误输出摘录:
:VG:generateDefaultFlavorDebugSources
:VG:compileDefaultFlavorDebugJava FAILED
C:\source\VG\src\main\java\com\myapp\errorhandling\VgErrorHandler.java:15: error: cannot find symbol
The vgcommon module is defined as an application module, not a library. vgcommon模块定义为应用程序模块,而不是库。 In its
build.gradle , instead of this line:
在其build.gradle中 ,而不是此行:
apply plugin: 'android'
use this: 用这个:
apply plugin: 'android-library'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.