【问题标题】:Some artifacts are miss when using Android Studio(Gradle) and Robolectric使用 Android Studio(Gradle) 和 Robolectric 时会遗漏一些工件
【发布时间】:2015-05-27 06:58:54
【问题描述】:

我下载Robolectric Samples 并通过Android Studio(版本1.2.1.1)导入。在android-api-19 下,我附加如下依赖项:

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.

有什么建议吗?

【问题讨论】:

  • 你在 build.gradle 文件中有存储库定义吗?
  • 是的@AlexFlorescu,这是我的依赖配置:` buildscript { repositories { jcenter() } dependencies { classpath "com.android.tools.build:gradle:1.2.3" } } repositories { maven { url "oss.sonatype.org/content/repositories/snapshots" } mavenLocal() mavenCentral() }`

标签: android-studio gradle robolectric


【解决方案1】:

如果您查看错误消息,您可以看到它正在查看的 Maven 存储库。我可以通过更新 my~/.m2 目录中的 settings.xml 文件来解决这个问题。

【讨论】:

    【解决方案2】:

    对我来说,问题是运行配置中的工作目录。 它指向错误的目录。

    选择运行,然后选择编辑配置...​。使用左上角的绿色 + 号添加新的运行配置并选择 Android JUnit。使您的 JUnit 运行配置如下所示:

    在 Use classpath of module 中选择您的 Android 应用程序的 app 模块。作为工作目录,使用您的应用程序模块的目录。 Class 是包含您的单元测试的文件(在本例中是您的 ctivityTest 类)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-07
      • 1970-01-01
      • 1970-01-01
      • 2014-09-09
      • 1970-01-01
      相关资源
      最近更新 更多