为什么Gradle不接受我的Android模块依赖?

时间:2014-07-09 13:01:47

标签: android gradle android-gradle

所以我尝试使用Gradle在IntelliJ IDEA中首次创建一个多模块项目。我花了一个小时阅读文档和各种教程和SO问题而无法解决这个简单的案例。我的结构:

-Project
   |-vg
   |-vgcommon

vgcommon是Android Gradle模块,而vg是Android Gradle应用程序(技术上也是一个模块)。

  • vg取决于vgcommon
  • vgcommon内容
  • vg没有,因为来自vgcommon的所有课程都是"未找到"。

这是我的gradle.build文件和setup.gradle。谁能看到我做错了什么?

settings.gradle (根级别)

include ':vgcommon', ':VG'

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

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
}

错误ouptut摘录:

:VG:generateDefaultFlavorDebugSources
:VG:compileDefaultFlavorDebugJava FAILED

C:\source\VG\src\main\java\com\myapp\errorhandling\VgErrorHandler.java:15: error: cannot find symbol

1 个答案:

答案 0 :(得分:2)

vgcommon模块被定义为应用程序模块,而不是库。在 build.gradle 中,而不是这一行:

apply plugin: 'android'

使用它:

apply plugin: 'android-library'