【问题标题】:How to resolve hamcrest jar file error in creating new project in android studio如何解决在android studio中创建新项目时的hamcrest jar文件错误
【发布时间】:2016-01-14 05:12:14
【问题描述】:

我在 android studio 中创建新项目时遇到此错误,我检查了库并有 hamcrest-core-1.3.jar 文件。请帮助我

    Error:A problem occurred configuring project ':app'.
    > Could not download hamcrest-core.jar (org.hamcrest:hamcrest-core:1.3)
   > Could not get resource 'https://jcenter.bintray.com/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar'.
  > Could not GET 'https://jcenter.bintray.com/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar'.
     > jcenter.bintray.com

【问题讨论】:

    标签: android-studio jar hamcrest


    【解决方案1】:

    错误不是因为 hamcrest-core-1.3.jar 文件。似乎 gradle 无法连接到 jcenter 并下载 junit.jar 。因此,请确保您的互联网连接并重建您的项目。通常 gradle 会下载所有必要的 jar。如果它没有尝试更新您的构建工具。

    【讨论】:

      【解决方案2】:

      在你的 build.gradle Module:app 上试试这个

      configurations.all {
              resolutionStrategy {
                  force 'org.hamcrest:hamcrest-core:1.3'
              }}
      

      参考:https://docs.gradle.org/current/dsl/org.gradle.api.artifacts.ResolutionStrategy.html

      【讨论】:

        【解决方案3】:

        根据我的经验,当我创建一个新项目时,我遇到了这个问题。 为了修复它,我从 build.gradle Module:app 中删除了以下依赖项。

        testCompile 'junit:junit:4.12'
        

        在那之后重建项目,问题就再也没有发生过。

        【讨论】:

          【解决方案4】:

          从 dependencies 下的 build.gradle Module:app 中删除以下行

          androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.1', {
                  exclude group: 'com.android.support', module: 'support-annotations'
              })
          

          【讨论】:

          • 最好解释一下为什么删除这些行会有帮助
          • 这对我来说真的很有效。赞!但那又是为什么呢?这背后有解释吗?
          【解决方案5】:

          我之前也遇到过同样的问题,在我的情况下,gradle 无法访问 jar 存储库。

          您可能需要:

          1. 首先确保您已连接到互联网
          2. 在 Android Studio 中设置代理设置(特别是如果您在工作环境/网络中使用它)或连接到开放网络

          【讨论】:

            【解决方案6】:

            转到 gradle.properties 并注释所有 systemProp 代理并重新同步

            它对我有用

            • Android 2.3.3

            【讨论】:

              【解决方案7】:

              在下禁用 Gradle 离线模式 文件 > 设置 > 构建、执行、部署 > 全局 Gradle 设置 禁用离线工作

              【讨论】:

                猜你喜欢
                • 1970-01-01
                • 2017-01-11
                • 1970-01-01
                • 1970-01-01
                • 2020-06-14
                • 2019-10-26
                • 2020-07-30
                • 1970-01-01
                • 1970-01-01
                相关资源
                最近更新 更多