运行gradle命令但未使用AndroidStudio

时间:2017-12-29 13:42:16

标签: android android-studio gradle android-gradle

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

$ 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,由于一些向后兼容性问题,我现在无法更新到最新版本。

我该如何解决这个问题?

谢谢,

1 个答案:

答案 0 :(得分:1)

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

确保在项目的build.gradle

中有类似的内容
allprojects {
    repositories {
        jcenter()
        maven { url 'https://maven.google.com' }
    }
}

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