38

After migrating from Android Studio 3.0 (Canary 5) to Android Studio 3.0 (Beta 1), and moving to latest gradle , i.e. 'com.android.tools.build:gradle:3.0.0-beta1'

When I try to gradle sync, it error stating below.

Failed to resolve: com.android.support:multidex:1.0.2 
Failed to resolve: com.android.support:multidex-instrumentation:1.0.2 

I check on Android Studio 3.0 Canary 9 - Failed to resolve packages, it doesn't solve my problem, as I already have this

    maven {
        url 'https://maven.google.com'
    }

I'm surprise it is even asking for multidex 1.0.2, as I only have in my build.gradle

compile 'com.android.support:multidex:1.0.1'

I check using ./gradlew app:dependencies | grep multidex, it shows the failures as below (across various flavors etc)

+--- com.android.support:multidex-instrumentation:1.0.2 FAILED
+--- com.android.support:multidex:1.0.1
+--- com.android.support:multidex:1.0.2 FAILED
+--- com.android.support:multidex:1.0.1 -> 1.0.2 FAILED

Where did the dependencies of multidex:1.0.2 and multidex-instrumentation:1.0.2 comes from? How could I solve this problem?

Elye
  • 53,639
  • 54
  • 212
  • 474

12 Answers12

97

Apparently my issue is I should post this:

maven {
    url 'https://maven.google.com'
}

in allprojects and not in buildscript (the subtle different has blinded me where the issue is), which then looks like this:

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

Thanks to M D for the pointers!

Tormod
  • 571
  • 5
  • 21
Elye
  • 53,639
  • 54
  • 212
  • 474
23

For me, the solution is move the google() item up to make sure it's before the jcenter(). And actually, I will put the google() in the first place of all the repositories.

blade
  • 2,285
  • 1
  • 18
  • 12
  • It seems something changed from jcenter about 3 days ago and broke our automated build system with this exact error(with no code change on our end in the interim). I would guess jcenter was declaring it had the lib and then returning 404 or something. Flipping the order worked, so have an upvote :-) – entropy Jun 11 '18 at 11:33
10

Need to add the following as well:

compile 'com.android.support:multidex:1.0.3'

After adding the above line, it worked for me in addition to the above answer

UVM
  • 9,776
  • 6
  • 41
  • 66
6

First you need to clean the project , and then rebuild it.

Build ----> Clean Project

Build ----> Rebuild Project

Milad Moosavi
  • 1,587
  • 10
  • 20
6
allprojects {
    repositories {
        google()
    }
}

worked for me instead of

allprojects {
    repositories {
        maven {
            url 'https://maven.google.com'
        }
    }
}
Tim Malseed
  • 6,003
  • 6
  • 48
  • 66
Rahul Tiwari
  • 6,851
  • 3
  • 49
  • 78
5

if you are in China, Please use

allprojects {
    respositories {
        google()
    }
}

to instead

allprojects {
    respositories {
        maven {
            url 'https://maven.google.com'
        }
    }
}

don't ask me why, I don't want to tell you.... may be 'https://maven.google.com' was selected by GFW?

Shaode Lu
  • 251
  • 1
  • 2
3

Adding google() in my allprojects solved my issue...

allprojects {
    repositories {
        jcenter()
        google()
    }
}
Shubhamhackz
  • 7,333
  • 7
  • 50
  • 71
2

If none of the above solutions are working then add mavenLocal() :

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

        mavenLocal()
        google()
    }
}
jeet.chanchawat
  • 5,842
  • 5
  • 38
  • 59
  • In my case I did it to load the maven from my local repository and it worked. So, I specified that if none other work then give a hit to it as well. – jeet.chanchawat Jan 13 '18 at 07:41
2

Move the google() item up to make sure it's before the jcenter().

repositories {
    jcenter()
    google()
}
0

Update all the gradle dependencies to latest version .. That’s it

0

my problem was network connection. I needed to connect to a vpn server to connect to jcenter

Mahdieh Shavandi
  • 4,906
  • 32
  • 41
0

In my cases, I have no need to requires multidex but I have added due to other dependencies requires[brightcove player]

So I have added below lines in gradle.properties and error was gone.

android.enableJetifier=true
anpVersion=6.18.3
Pratik Dodiya
  • 2,337
  • 1
  • 19
  • 12