Home » Android » Could not find com.android.tools.build:aapt2:3.2.0

Could not find com.android.tools.build:aapt2:3.2.0

Posted by: admin March 11, 2020 Leave a comment

Questions:

AndroidStudio3.2 Canary14 fails clean-and-rebuild with the following error

Could not find com.android.tools.build:aapt2:3.2.0-alpha14-4748712.
Searched in the following locations:
    file:~/Library/Android/sdk/extras/m2repository/com/android/tools/build/aapt2/3.2.0-alpha14-4748712/aapt2-3.2.0-alpha14-4748712.pom
    file:~/Library/Android/sdk/extras/m2repository/com/android/tools/build/aapt2/3.2.0-alpha14-4748712/aapt2-3.2.0-alpha14-4748712-osx.jar
    file:~/Library/Android/sdk/extras/google/m2repository/com/android/tools/build/aapt2/3.2.0-alpha14-4748712/aapt2-3.2.0-alpha14-4748712.pom
    file:~/Library/Android/sdk/extras/google/m2repository/com/android/tools/build/aapt2/3.2.0-alpha14-4748712/aapt2-3.2.0-alpha14-4748712-osx.jar
    file:~/Library/Android/sdk/extras/android/m2repository/com/android/tools/build/aapt2/3.2.0-alpha14-4748712/aapt2-3.2.0-alpha14-4748712.pom
    file:~/Library/Android/sdk/extras/android/m2repository/com/android/tools/build/aapt2/3.2.0-alpha14-4748712/aapt2-3.2.0-alpha14-4748712-osx.jar
    https://jcenter.bintray.com/com/android/tools/build/aapt2/3.2.0-alpha14-4748712/aapt2-3.2.0-alpha14-4748712.pom
    https://jcenter.bintray.com/com/android/tools/build/aapt2/3.2.0-alpha14-4748712/aapt2-3.2.0-alpha14-4748712-osx.jar
Required by:
    project :app
How to&Answers:

Beginning with Android Studio 3.2 Canary 11, the source for AAPT2 (Android Asset Packaging Tool 2) is Google’s Maven repository.

To use AAPT2, make sure that you have a google() dependency in your build.gradle file, as shown here:

buildscript {
  repositories {
      google() // here
      jcenter()
  }
  dependencies {
      classpath 'com.android.tools.build:gradle:3.2.0-alpha12'
  }
} 
allprojects {
  repositories {
      google() // and here
      jcenter()
  }
}

The new version of AAPT2 fixes many issues, including improved handling of non-ASCII characters on Windows.

Adding the repositories in the buildscript is not sufficient, you need to add it also in allprojects.

Source: https://developer.android.com/studio/releases/#aapt2_gmaven

Answer:

Are you opening a very old project?
If so, make sure your app’s build.gradle has:

apply plugin: 'com.android.application'

repositories {
    google()
    jcenter()
} 

(That solved it for me anyways)

Answer:

Just add google() on your buidscript and allprojects then rebuild the project.

buildscript {
    repositories {
        google() // `enter code here`
    }
 }

allprojects {
    repositories {
        google() // `<-- here`
    }
}

Answer:

I resolve this issue by changing the “distributionUrl” in android/gradle/gradle-wrapper.properties.

The default value was https\://services.gradle.org/distributions/gradle-4.10.2-all.zip and I changed it to https\://services.gradle.org/distributions/gradle-5.4.1-all.zip and the error is gone.

Answer:

Update your app’s build.grade file dependency with the updated version of grade

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

Follow android studio suggestion of the version to update to.
after your grade classpath update and re-sync your app.

After all this restart your android studio.

Answer:

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    repositories {
        jcenter()
        google()  //导入旧版本项目时,一般来说该处依赖会在更改classpath中gradle版本是自动添加
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.3.0'
        classpath 'com.google.gms:google-services:3.0.0'
    }
}

allprojects {
    repositories {
       /*
        解决报错:Could not find com.android.tools.build:aapt2:3.3.0-5013011.
        Beginning with Android Studio 3.2 Canary 11, the source for AAPT2 (Android Asset Packaging Tool 2) is Google's Maven repository.
        To use AAPT2, make sure that you have a google() dependency in your build.gradle file, as shown here:
        */
        google() //但是此处不会,需要自主添加
        jcenter()
    }
}

Answer:

I am in Iran, and google repository is restricted in my location. When I change my IP to another country, this problem solved. It seems you may have an internet connection problem when this error happens.

Answer:

The solution is a four-step process,
1. change the classpath in build.gradle to the desired version.
2. Sync Now
3. After it downloads all the files, you can delete the new and add the previous version in Gradle.
4. Sync Now

Follow the link below,

https://www.getsuyodev.com/could-not-resolve-com-android-tools-buildaapt23-5-0-5435860/

Answer:

I had this error message:

Could not download aapt2-osx.jar
(com.android.tools.build:aapt2:3.5.0-5435860): No cached version
available for offline mode

Even if I had defined all the necessary dependencies for my proyect, and the right configuration into my build.gradle:

apply plugin: 'com.android.application'

repositories {
    google()
    jcenter()
} 

The error still happening, but this message gave me a clue of what was happening:

No cached version available for offline mode

So I discovered that I was working offline, you need to uncheck the “offline mode” then Android Studio will be able to download the necessary resources to create the project.

enter image description here

When your project is working again, you can check again to work offlin.

Answer:

you need to tape in the: build.gradle ()
and type google()
and this option do it in buildscript & allproject section

Answer:

if google() not fixied then
File -> Setting -> Build, Execution, Deployment -> Gradle

Then Uncheck Ofline Work, Done.