【问题标题】:Error running gradle command but not using AndroidStudio运行 gradle 命令但未使用 Android Studio 时出错
【发布时间】:2017-12-29 13:42:15
【问题描述】:

我有一个使用 com.android.support.test:runner:1.0.1 的项目,我可以使用 AndroidStudio 运行和单元测试,但是当我尝试使用命令行运行项目时,我收到以下错误:

$ sh gradlew :myproject:clean

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring project ':myproject'.
> Could not resolve all dependencies for configuration ':myproject:_normalDebugAndroidTestApkCopy'.
   > Could not find com.android.support:support-annotations:25.0.2.
     Searched in the following locations:
         file:/Users/Joan/SDKs/android-sdk/extras/android/m2repository/com/android/support/support-annotations/25.0.2/support-annotations-25.0.2.pom
         file:/Users/Joan/SDKs/android-sdk/extras/android/m2repository/com/android/support/support-annotations/25.0.2/support-annotations-25.0.2.jar
         file:/Users/Joan/Development/myproject/git/android-tag/src/myproject/sdk-manager/com/android/support/support-annotations/25.0.2/support-annotations-25.0.2.jar
     Required by:
         project :myproject
   > Could not find com.android.support.test:runner:1.0.1.
     Searched in the following locations:
         file:/Users/Joan/SDKs/android-sdk/extras/android/m2repository/com/android/support/test/runner/1.0.1/runner-1.0.1.pom
         file:/Users/Joan/SDKs/android-sdk/extras/android/m2repository/com/android/support/test/runner/1.0.1/runner-1.0.1.jar
         file:/Users/Joan/Development/myproject/git/android-tag/src/myproject/sdk-manager/com/android/support/test/runner/1.0.1/runner-1.0.1.jar
     Required by:
         project :myproject
   > Could not find com.android.support.test:rules:1.0.1.
     Searched in the following locations:
         file:/Users/Joan/SDKs/android-sdk/extras/android/m2repository/com/android/support/test/rules/1.0.1/rules-1.0.1.pom
         file:/Users/Joan/SDKs/android-sdk/extras/android/m2repository/com/android/support/test/rules/1.0.1/rules-1.0.1.jar
         file:/Users/Joan/Development/myproject/git/android-tag/src/myproject/sdk-manager/com/android/support/test/rules/1.0.1/rules-1.0.1.jar
     Required by:
         project :myproject

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 4.437 secs

我正在使用 gradle 2.3.3,由于一些向后兼容性问题,我目前无法更新到最新版本。

我该如何解决这个问题?

谢谢,

【问题讨论】:

    标签: android android-studio gradle android-gradle-plugin


    【解决方案1】:

    您似乎错过了build.gradle 中的maven { url 'https://maven.google.com' }。这就是它只搜索 maven 缓存的原因。

    确保您的项目的build.gradle 中有类似的内容:

    allprojects {
        repositories {
            jcenter()
            maven { url 'https://maven.google.com' }
        }
    }
    

    此外,您可以使用./gradlew :myproject:clean 而不是sh gradlew :myproject:clean 运行Gradle 任务。

    【讨论】:

      猜你喜欢
      • 2019-10-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-09-29
      • 2013-05-12
      • 1970-01-01
      相关资源
      最近更新 更多