2015-04-03 37 views
3

我在項目中使用谷歌的volley lib。我將它作爲模塊添加,但是在編譯期間會出現以下錯誤。如何修復抽排測試編譯

Error

這裏是目錄結構:

dir_structure

我嘗試添加

// testing 
testCompile 'org.robolectric:robolectric:2.4' 
testCompile 'junit:junit:4.+' 

到應用程序的build.gradle,但這並沒有幫助。

所以顯而易見的問題是如何使它工作?

UPDATE

排球的build.gradle

buildscript { 
    repositories { 
     mavenCentral() 
    } 
    dependencies { 
     classpath 'com.android.tools.build:gradle:1.1.0+' 

     // testing 
     testCompile 'org.robolectric:robolectric:2.4' 
     testCompile 'junit:junit:4.+' 
    } 
} 

apply plugin: 'com.android.library' 

android { 
    compileSdkVersion 19 
    buildToolsVersion = '21.1.0' 
} 

apply from: 'rules.gradle' 

應用的build.gradle

apply plugin: 'com.android.application' 

android { 
    compileSdkVersion 22 
    buildToolsVersion "19.1.0" 

    defaultConfig { 
     applicationId "com.example.vjdhama.project" 
     minSdkVersion 15 
     targetSdkVersion 22 
     versionCode 1 
     versionName "1.0" 
    } 
    buildTypes { 
     release { 
      minifyEnabled false 
      proguardFiles getDefaultProguardFile('proguard-android.txt'),  'proguard-rules.pro' 
     } 
    } 
} 

dependencies { 
    compile fileTree(dir: 'libs', include: ['*.jar']) 
    compile 'com.android.support:appcompat-v7:22.0.0' 

    compile project(":volley") 
} 

錯誤

/home/vjdhama/Documents/Coding/Android/project/volley/build.gradle 
Error:Error:line (18)Gradle DSL method not found: 'testCompile()' 
Possible causes:<ul><li>The project 'project' may be using a version of Gradle that does not contain the method. 
<a href="openGradleSettings">Gradle settings</a></li><li>The build file may be missing a Gradle plugin. 
<a href="apply.gradle.plugin">Apply Gradle plugin</a></li> 
+0

是必需的依賴於排球,而不是應用程序模塊。你可以分享排球構建Gradle或者排球的位置 – 2015-04-03 18:16:57

+0

我更新了問題。我也嘗試使用'androidtestcompile'建議在[這裏](http://stackoverflow.com/questions/25252637/gradle-build-script-error-occurs-when-i-attempt-to-use-testcompile-in-依賴),但它也沒有工作。 – vjdhama 2015-04-04 10:03:33

+0

您將依賴關係添加到錯誤的地方。正確的文件,但應爲構建腳本 – 2015-04-04 10:31:20

回答

0

+1同樣的問題。我似乎仍然使用我的更大的Android項目中的庫,但測試不運行。看起來Volley的最新版本已經打​​破了build.gradle中的依賴關係。不是因爲它的答案似乎並沒有工作,但也許你會加入

dependencies { 
    testCompile 'org.robolectric:robolectric:2.3' 
    testCompile 'junit:junit:4.11' 
    testCompile 'org.mockito:mockito-core:1.9.5' 
} 

凌空的的build.gradle文件的底部有比我

更多的運氣,我可以得到運行失敗所有測試而不是失敗構建。這是我想的。從凌空

完整的build.gradle:

buildscript { 
    repositories { 
     jcenter() 
    } 
    dependencies { 
     classpath 'com.android.tools.build:gradle:1.2.3' 
    } 
} 

apply plugin: 'com.android.library' 

android { 
    compileSdkVersion 22 
    buildToolsVersion = '22.0.1' 
} 

apply from: 'rules.gradle' 

dependencies { 
    testCompile 'org.robolectric:robolectric:2.3' 
    testCompile 'junit:junit:4.11' 
    testCompile 'org.mockito:mockito-core:1.9.5' 
}