20

When I try to build may Android project from command line, I get following error messages:

A problem occurred configuring project ':mylib'. Could not resolve all files for configuration ':mylib:classpath'. Could not find com.android.tools.build:gradle:3.0.0. Searched in the following locations:
https://jcenter.bintray.com/com/android/tools/build/gradle/3.0.0/gradle-3.0.0.pom
https://jcenter.bintray.com/com/android/tools/build/gradle/3.0.0/gradle-3.0.0.jar https://repo1.maven.org/maven2/com/android/tools/build/gradle/3.0.0/gradle-3.0.0.pom
https://repo1.maven.org/maven2/com/android/tools/build/gradle/3.0.0/gradle-3.0.0.jar Required by: project :mylib

And when I try to access for example the address "https://jcenter.bintray.com/com/android/tools/build/gradle/3.0.0/gradle-3.0.0.pom" directly via browser, following is shown:

{
  "errors" : [ {
    "status" : 404,
    "message" : "Could not find resource"
  } ]
}

The root gradle file contains following code:

dependencies {
  classpath 'com.android.tools.build:gradle:3.0.0'

  // NOTE: Do not place your application dependencies here; they belong
  // in the individual module build.gradle files
}

...

allprojects {
  repositories {
    jcenter()
    google()
  }
}

And the file gradle-wrapper.properties contains following values:

#Fri Oct 27 10:09:16 CEST 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip

The same configuration works fine if I compile from Android Studio 3.0. But if I try to compile directly from the command line, I receive the error.

Could anybody help me?

Sneh Pandya
  • 8,197
  • 7
  • 35
  • 50
tangens
  • 665
  • 2
  • 11
  • 17

2 Answers2

30

My question is "./gradlew assembleDebug" appeared,Android studio build is successful。I solved it this way

repositories {
    jcenter()
    google()
}

or

repositories {
    jcenter()
    maven {
        url 'https://maven.google.com'
    }
}
Felix Zhou
  • 301
  • 2
  • 4
  • If you're using a version of Gradle lower than 4.1, use 2nd option: https://developer.android.com/studio/build/dependencies.html – jbarradas Jan 14 '18 at 22:42
  • 2
    In my case it was specifically the addition of `google()` in repositories that resolved the issue. (`jcenter()` was already present). – BenLeah Mar 08 '18 at 09:49
  • Note that try to put this `jcenter()` and `google()` in **ALL** build.grande to resolve the error. – 林果皞 May 08 '18 at 09:32
4

I am not quite sure, but maybe you should try putting the repositories tag at the same level of the dependencies tag. So:

buildscript {
    repositories {
        ...
    }
    dependencies {
        ...
    }
}
Wout
  • 315
  • 4
  • 10
  • Thank you, that was the solution. I just had the same idea (of course only after I wrote the request ;) ) and it worked. – tangens Oct 30 '17 at 10:50