2014-07-09 40 views
0

所以我試圖在IntelliJ IDEA中使用Gradle首次創建一個多模塊項目。我花了一個小時閱讀文檔和各種教程和SO問題,卻無法解決這個簡單的問題。我的結構:爲什麼Gradle不能在我的Android模塊依賴關係中使用?

-Project 
    |-vg 
    |-vgcommon 

vgcommon是一個Android搖籃模塊,而vg是一個Android搖籃應用(技術上也是一個模塊)。

  • 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 

回答

2

的vgcommon模塊定義爲應用模塊,而不是一個庫。在其的build.gradle,而不是這一行:

apply plugin: 'android' 

使用本:

apply plugin: 'android-library' 
+0

感謝。對其他人的提示:同時刪除'productFlavors'部分,因爲圖書館沒有這種東西。 – Nilzor