2015-05-27 27 views
2

我下載了Robolectric Samples並由Android Studio(版本1.2.1.1)導入。下android-api-19我追加依賴性等如下:使用Android Studio(Gradle)時會丟失一些工件並且Robolectric

dependencies { 
testCompile "junit:junit:4.10" 
testCompile "org.json:json:20080701" 
testCompile "org.ccil.cowan.tagsoup:tagsoup:1.2" 
testCompile "org.assertj:assertj-core:1.7.0" 
testCompile "org.robolectric:robolectric:${robolectricVersion}" 
testCompile "org.robolectric:android-all:4.4_r1-robolectric-1" 
testCompile "org.robolectric:shadows-core:3.0-rc2" 

} 

我可以通過Project視圖看到jsontagsoupshadows-coreandroid-all庫。我也可以在$ {GRADLE_HOME} /caches/modules-2/files-2.1目錄下看到它們。但是當我使用Gradle Test運行該項目時,會發生錯誤:


Unable to resolve artifact: Missing: 
---------- 
1) org.ccil.cowan.tagsoup:tagsoup:jar:1.2 

    Try downloading the file manually from the project website. 

    Then, install it using the command: 
     mvn install:install-file -DgroupId=org.ccil.cowan.tagsoup -DartifactId=tagsoup -Dversion=1.2 -Dpackaging=jar -Dfile=/path/to/file 

    Alternatively, if you host your own repository you can deploy the file there: 
     mvn deploy:deploy-file -DgroupId=org.ccil.cowan.tagsoup -DartifactId=tagsoup -Dversion=1.2 -Dpackaging=jar -Dfile=/path/to/file -Durl=[url] -DrepositoryId=[id] 

    Path to dependency: 
    1) org.apache.maven:super-pom:pom:2.0 
    2) org.ccil.cowan.tagsoup:tagsoup:jar:1.2 

2) org.robolectric:android-all:jar:4.4_r1-robolectric-1 

    Try downloading the file manually from the project website. 

    Then, install it using the command: 
     mvn install:install-file -DgroupId=org.robolectric -DartifactId=android-all -Dversion=4.4_r1-robolectric-1 -Dpackaging=jar -Dfile=/path/to/file 

    Alternatively, if you host your own repository you can deploy the file there: 
     mvn deploy:deploy-file -DgroupId=org.robolectric -DartifactId=android-all -Dversion=4.4_r1-robolectric-1 -Dpackaging=jar -Dfile=/path/to/file -Durl=[url] -DrepositoryId=[id] 

    Path to dependency: 
    1) org.apache.maven:super-pom:pom:2.0 
    2) org.robolectric:android-all:jar:4.4_r1-robolectric-1 

3) org.json:json:jar:20080701 

    Try downloading the file manually from the project website. 

    Then, install it using the command: 
     mvn install:install-file -DgroupId=org.json -DartifactId=json -Dversion=20080701 -Dpackaging=jar -Dfile=/path/to/file 

    Alternatively, if you host your own repository you can deploy the file there: 
     mvn deploy:deploy-file -DgroupId=org.json -DartifactId=json -Dversion=20080701 -Dpackaging=jar -Dfile=/path/to/file -Durl=[url] -DrepositoryId=[id] 

    Path to dependency: 
    1) org.apache.maven:super-pom:pom:2.0 
    2) org.json:json:jar:20080701 

4) org.robolectric:shadows-core:jar:19:3.0-rc2 

    Try downloading the file manually from the project website. 

    Then, install it using the command: 
     mvn install:install-file -DgroupId=org.robolectric -DartifactId=shadows-core -Dversion=3.0-rc2 -Dclassifier=19 -Dpackaging=jar -Dfile=/path/to/file 

    Alternatively, if you host your own repository you can deploy the file there: 
     mvn deploy:deploy-file -DgroupId=org.robolectric -DartifactId=shadows-core -Dversion=3.0-rc2 -Dclassifier=19 -Dpackaging=jar -Dfile=/path/to/file -Durl=[url] -DrepositoryId=[id] 

    Path to dependency: 
    1) org.apache.maven:super-pom:pom:2.0 
    2) org.robolectric:shadows-core:jar:19:3.0-rc2 

---------- 
4 required artifacts are missing. 

任何建議?

+0

您是否在build.gradle文件中有存儲庫定義? –

+0

是@AlexFlorescu,這是我的依賴CONFIGS:' buildscript { 庫{ jcenter() } 依賴{ 類路徑 「com.android.tools.build:gradle:1.2.3」 }} () 知識庫{mavenlocal() mavenCentral() } maven {url「https://oss.sonatype.org/content/repositories/snapshots」} } – Hicto

回答

0

如果你看看錯誤消息,你可以看到它正在看的Maven倉庫。我能夠通過更新我的~/.m2目錄中的settings.xml文件來解決此問題。

0

我的問題是運行配置中的工作目錄。 它指向錯誤的目錄。

選擇運行,然後編輯配置...。使用左上角的綠色+符號添加新的運行配置並選擇Android JUnit。讓你的JUnit運行配置如下所示: enter image description here

在使用模塊的類路徑中選擇您的Android應用程序的應用模塊。作爲工作目錄使用您的應用程序模塊的目錄。類是包含你的單元測試的文件(在這種情況下是你的ctivityTest類)。

相關問題