Android CI build: Could not find aapt2-proto.jar

AndroidAndroid StudioContinuous IntegrationJcenter

Android Problem Overview


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()
}

Android Solutions


Solution 1 - Android

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

Solution 2 - Android

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

Solution 3 - Android

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()
}

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionestnView Question on Stackoverflow
Solution 1 - AndroidHedeHView Answer on Stackoverflow
Solution 2 - AndroidNail ShaykhrazievView Answer on Stackoverflow
Solution 3 - AndroidKhemraj SharmaView Answer on Stackoverflow