118

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
Arunabh Das
  • 13,212
  • 21
  • 86
  • 109

18 Answers18

266

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

Community
  • 1
  • 1
Izabela Orlowska
  • 7,431
  • 2
  • 20
  • 33
48

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)

Pico
  • 481
  • 3
  • 4
  • The important part is the "google()" repository dependency. – Izabela Orlowska May 11 '18 at 10:59
  • 12
    For me it was the order. I had `google()` but it was down in the list of repos. Moving it on top of the list of repos fixed the issue. – Ezekiel Sebastine Oct 23 '18 at 09:16
  • this should be accepted... (for opening old projects at least)... the key repository was google() and it can be placed either to app's build.gradle or rather in project's build.gradle under allprojects > repositories, where jcenter() usually already is – Lukáš Řádek May 02 '19 at 14:49
21

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

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

allprojects {
    repositories {
        google() // `<-- here`
    }
}
V-rund Puro-hit
  • 5,518
  • 9
  • 31
  • 50
fMadTech
  • 308
  • 3
  • 5
10

I am in Iran, and some of google's repositories are restricted in my location. When I changed my IP to another country, this problem was solved. It seems you may have an internet connection problem when this error happens.

AliSh
  • 10,085
  • 5
  • 44
  • 76
  • 1
    actually i am using vpn but the problem still remind and i cant run the project! – Nadia Apr 14 '20 at 14:16
  • That's interesting. I was using a VPN that tunnels to **Netherlands** and when I tunneled it to US it downloaded the aapt tools. What's going on?. – Abdifatah Mohamed May 20 '21 at 14:23
5

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.

Samson Ayalew
  • 359
  • 3
  • 8
4

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.

Jorgesys
  • 124,308
  • 23
  • 334
  • 268
3

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.

Amir Ajorloo
  • 85
  • 1
  • 5
2
// 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()
    }
}
林嗳莫
  • 31
  • 2
2

I have same problem even with google() fix by change this lines

change this in build.gradle

classpath 'com.android.tools.build:gradle:3.4.0'

to this

classpath 'com.android.tools.build:gradle:4.0.2'

and change this in gradle-wrapper.properties

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

to this

distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip
Radesh
  • 13,084
  • 4
  • 51
  • 64
0

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
Zoe
  • 27,060
  • 21
  • 118
  • 148
hanif s
  • 488
  • 1
  • 3
  • 19
0

3 steps to fix it below within the video

  1. Gradle bar to the right
  2. Toggle offline mode sign
  3. Rebuild en enjoy! https://www.youtube.com/watch?v=8W3a6_xwGOo&
  • After having a "Could not resolve ..." error and Android Studio (or gradle plugin or whatever) suggesting to look at offline mode, I couldn't find it! I had looked through the settings, and various gradle properties and settings files. This offline mode symbol in the gradle bar on right did it for me, thanks! – hwertz Mar 03 '22 at 20:53
0

In my case, I was able to resolve it by updating "Android SDK Build-Tools" to the latest version.

In Android studio, Goto Tools -> SDK Manager -> Select SDK tools tab -> check whether any update available for the Android SDK Build - Tools (updated to the latest v30.0.0).

enter image description here

Prasanna Narshim
  • 778
  • 10
  • 14
0

Go to settings.gradle and remove projectRoot.name file

Mahdi Giveie
  • 630
  • 1
  • 8
  • 25
0

Problem happened to me when i opened my old project

Can be fixed by upgrading the tools gradle

classpath "com.android.tools.build:gradle:4.0.2"

0

Unfortunality non of the answers above was complete enough, however this work for me . Just make sure your build.gradel has all of the following

buildscript {
    repositories {
        google() // Check if this Google exists and is in the first
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.5.0'
    }
}

allprojects {
    repositories {
        google() // Check if this Google exists and is in the first
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}
Abdelsalam Hamdi
  • 465
  • 3
  • 13
0

important: if your country is blocked by android related sites(you receive 403 from android related sites like https://dl.google.com/dl/android) , make sure you have a working VPN, you may wonder if it is important, but i assure you it is important

after making sure you have a working internet connection, do the following steps

  1. make sure your android studio and gradle version are compatible. check it here

  2. check if you have these blocks in build.gradle(project)

    .
    .
    .
      repositories {
        google()
        mavenCentral()
    }
    
    .
    .
    .
    
      allprojects {
        repositories {
            google()
            mavenCentral()
        }
    }
    .
    .
    .
    

after doing above steps, if the app can't be run, do the following

  1. close android studio
  2. delete gradle caches(ubuntu: home/.gradle/caches)
  3. open android studio and let gradle build the project. then try to run the app(it is important to have a working internet connection specially in this step, some proxies may get response from some sites, but get blocked on others and the build error doesn't show the correct problem)
Mohammad cs
  • 191
  • 1
  • 10
-1

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

DonMoh
  • 1
-2

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

Then Uncheck Ofline Work, Done.

Saljith Kj
  • 125
  • 2
  • 4