51

I have failing build on a Bitbucket CI server:

> Could not resolve all artifacts for configuration ':classpath'.
   > Could not find aapt2-proto.jar (com.android.tools.build:aapt2-proto:0.3.1).
     Searched in the following locations:
         https://jcenter.bintray.com/com/android/tools/build/aapt2-proto/0.3.1/aapt2-proto-0.3.1.jar

I searched similar questions that suggested the Google Maven repository is missing, but I am not missing it. Top level build file:

buildscript {

    repositories {
        jcenter()
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.1'
        classpath 'com.neenbedankt.gradle.plugins:android-apt:1.8'
        classpath 'com.jakewharton:butterknife-gradle-plugin:8.8.0'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin"
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        maven { url "https://jitpack.io" }
    }
}

And my app level build file:

buildscript {
    repositories {
        maven { url 'https://maven.fabric.io/public' }
        google()
    }

    dependencies {
        classpath 'io.fabric.tools:gradle:1.26.1'
    }
}
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'io.fabric'

repositories {
    maven { url 'https://maven.fabric.io/public' }
    google()
    mavenCentral()
}
M.Ricciuti
  • 11,070
  • 2
  • 34
  • 54
estn
  • 1,203
  • 1
  • 12
  • 25
  • 5
    opening https://jcenter.bintray.com/com/android/tools/build/aapt2-proto/0.3.1/aapt2-proto-0.3.1.jar in browser gives 404, could it be broken jcenter / the library was moved ? – estn Oct 23 '18 at 08:33
  • check here also: https://stackoverflow.com/a/52979557/8034839 – shizhen Oct 25 '18 at 03:44

3 Answers3

69

Try moving the google() method to the top of its execution block.

Maybe it's the order of repositories it searches in that causes the issue.

So for example, change this:

repositories {
  maven { url 'https://maven.fabric.io/public' }
  google() // from here
  mavenCentral()
}

To this:

repositories {
  google() // to here
  maven { url 'https://maven.fabric.io/public' }
  mavenCentral()
}

If that doesn't help, instead of calling the google() method, try changing it to this:

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

UPDATE

If all of the above didn't help - make sure your gradle version is at least 3.0.0:

dependencies {
  classpath 'com.android.tools.build:gradle:3.2.1'
}

And the gradle-wrapper version is at least 4.1:

Usually located here: project_name/gradle/wrapper/gradle-wrapper.properties

distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.2-all.zip

Source

HedeH
  • 2,869
  • 16
  • 25
  • A problem occurred configuring root project 'XXXXXXXXXx'. > Could not resolve all artifacts for configuration ':classpath'. > Could not find aapt2-proto.jar (com.android.tools.build:aapt2-proto:0.3.1). Searched in the following locations: https://plugins.gradle.org/m2/com/android/tools/build/aapt2-proto/0.3.1/aapt2-proto-0.3.1.jar – Viswanath Kumar Sandu Oct 23 '18 at 10:08
  • 2
    This in combination with upgrading the gradle wrapper version to 4.10.2 worked for me – Dean Oct 23 '18 at 14:04
  • Moving google() to the very top, before maven and jcenter solved it for me on Android Studio 3.2.1. – Matt from vision.app Oct 23 '18 at 16:44
22

Upgrading the Gradle wrapper (in gradle-wrapper.properties) to gradle-4.10.2-all.zip fixed the problem to me.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
  • 5
    Upgrading from gradle wrapper version 4.6 to 4.10.2 did the trick for me! – Dean Oct 23 '18 at 13:44
  • Upgrading Gradle worked but had to update kotlin-stdlib-common to 1.3.0-rc-198 too (131 before). – harry248 Oct 24 '18 at 06:54
  • upgrading the wrapper version gives --- Failed to resolve: org.jetbrains.kotlin:kotlin-stdlib-common:1.3.0-rc-131 --- error. How to fix this – png Oct 24 '18 at 19:40
0

Update Gradle Version

From the android gradle release page you can check compatible version for your gradle plugin.

Update gradle version in gradle-wrapper.properties located inside yourProject/gradle/wrapper

distributionUrl=https\://services.gradle.org/distributions/gradle-4.4.0-all.zip
Plugin version  Required Gradle version

   2.3.0+             3.3+
   3.0.0+             4.1+
   3.1.0+             4.4+

Note that order matters. google() should be top of any plugin repo.

For Android Studio version > 3.0

buildscript {
  repositories {
      google() // move it to top
      jcenter()
  }
  dependencies {
      classpath 'com.android.tools.build:gradle:3.2.1' // your Android Studio Version
  }
} 
allprojects {
  repositories {
      google() // move it to top
      jcenter()
}

google() plugin is needed since Android Studio version 3.0 or higher.

For Android Studio version < 3.0

buildscript {
  repositories {
      maven {
       url 'https://maven.google.com/'
       name 'Google'
      }
      jcenter()
  }
  dependencies {
      classpath 'com.android.tools.build:gradle:2.3.0' // your Android Studio Version
  }
} 
allprojects {
  repositories {
      maven {
       url 'https://maven.google.com/'
       name 'Google'
      }
      jcenter()
}
Community
  • 1
  • 1
Khemraj Sharma
  • 57,232
  • 27
  • 203
  • 212