23

I've created a new project, but when it finish the first compile the new project return an error:

Error:Could not find common.jar (android.arch.core:common:1.1.0).
Searched in the following locations:
    https://jcenter.bintray.com/android/arch/core/common/1.1.0/common-1.1.0.jar

I've really no idea how to resolve it, hope you can help me!

Screenshots on how i'm creating a new project:

Creating an android project 1

Creating an android project 2

Creating an android project 3

Creating an android project 4

Build.gradle

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.2.2'

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

allprojects {
    repositories {
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

setting.gradle

include ':app'

I've added the gradle files because i'm thinking there is a problem there.

G. Ciardini
  • 1,210
  • 1
  • 17
  • 32

2 Answers2

54

Add maven { url 'https://maven.google.com' } before jcenter() in

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

it will work


Update :

Note : google() and maven { url 'https://maven.google.com' } are pointing to the same repo, google() is a Google's Maven repo shortcut. You can add google() instead of maven { url 'https://maven.google.com' } IF you are using :

Gradle >= v.4.x+

Android Studio >= 3.x+

Gradle plugin for Android >= 3.x+

Bryant Makes Programs
  • 1,493
  • 2
  • 17
  • 39
E.Abdel
  • 1,992
  • 1
  • 13
  • 24
  • 7
    It seems the order is important – Roberto May 29 '18 at 09:03
  • 1
    Can anyone explain why the order is important? – hiddeneyes02 Jul 02 '18 at 07:51
  • 2
    @hiddeneyes02 it seems to be a bug : instead of looking in the next repo, gradle will directly generate an error if it does not find what it looks for in the current one, so mooving google's repo to the top is the working workaround for the moment – E.Abdel Jul 02 '18 at 08:00
10

In both sections, you need to add Google repo

 repositories {
    google() 
    jcenter()
}

If you upgraded Android Studio this would be done for you

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
  • Could not find method google() for arguments [] on repository container. – G. Ciardini May 28 '18 at 16:18
  • The company i work for they all use android 2.2 so i need to use it too, it's sad i know :/ – G. Ciardini May 28 '18 at 16:20
  • You need to either click the link to view the alternate URL or upgrade to use Gradle 4.1 (and configure Android Studio to use it), also mentioned in the link – OneCricketeer May 28 '18 at 16:24
  • 2
    Note that the order is important sometimes, my build was failing in CircleCI because `jcenter()` was in the previous line than `google()`, so it was searching architecture components in jcenter, then failing – voghDev Jun 08 '18 at 09:32
  • 1
    @voghDev Thank you for this! I was floored why my CI was complaining, this solved it for me. – Dominik G. Jun 08 '18 at 12:06
  • @vogh There's an open Android bug tracker I found a few week ago for resolving that – OneCricketeer Jun 08 '18 at 13:29
  • Indeed @cricket_007, more colleagues here had the same problem. For the moment we have the workaround of adding `google()` before `jcenter()` :-) – voghDev Jun 11 '18 at 12:37