Build errors after Android Studio 3.2.1 upgrade

60,595

Solution 1

For Android Studio 3.2.1 update

Just add google() in root level build.gradle

buildscript {
    repositories {
        google()   //  <--here
        jcenter()
    }
 }

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

and see the magic - error is gone.

Solution 2

The project gradle version is pretty old:

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

And you are using Android Studio v3.2.1 so, update the gradle:

classpath 'com.android.tools.build:gradle:3.2.0' // or 3.2.1 maybe

Also, as you can see, it was looking for some packages in :

file:/C:/Users/sandeepk2/AppData/Local/Android/Sdk/extras/m2repository/com/android/tools/build/aapt2/3.2.1-4818971/aapt2-3.2.1-4818971.pom

Which means you probably forgot to add google() as the top level repository. Just add google()

to your repositories in your root build.gradle.

Solution 3

To get this solved

Firstly download the missing Jar file from the link below. I see you are missing version 3.2.1-4818971

https://dl.google.com/dl/android/maven2/com/android/tools/build/aapt2/3.2.1-4818971/aapt2-3.2.1-4818971-windows.jar

Switch your folder structure from Android to Project.

FolderStructure

Now navigate to the libs folder inside the app - build folder. (If the libs folder does not exist, you can create it by right clicking on the app folder - select New - select Directory.)

LibsFolder

Paste the downloaded.jar file inside libs folder. Right click on the jar file and at the bottom click on Add as library. This will take care of adding implementation files('libs/library_name.jar') in build.gradle [You don't have to manually enter this in your build file].

AddAsLibrary

Everything should be okay once you sync after doing the above. Here is the source link to this solution: https://developer.android.com/studio/command-line/aapt2#download_aapt2

Let me know if you run into any other issues whilst doing the above.

Solution 4

Yeah, as d4rkcon said download https://dl.google.com/dl/android/maven2/com/android/tools/build/aapt2/3.2.1-4818971/aapt2-3.2.1-4818971-windows.jar But you can do simplier - just put this file in directory where Andoid Studio is trying to find it. If you don't have directories like /tools/build/aapt2/3.2.1-4818971/ in AndroidSDK folder just create them and then put aapt2-3.2.1-4818971-windows.jar file in.

Solution 5

Add Google repository in your build.gradle(Project:xxxxx)

allprojects {
    repositories {
        google()
    }
}
Share:
60,595
sandeep kakkar
Author by

sandeep kakkar

Updated on July 05, 2022

Comments

  • sandeep kakkar
    sandeep kakkar almost 2 years

    I am building a sample project from Udacity. This was working fine till now, but after upgrading to Android Studio 3.2.1, I am facing the build error below.

    Gradle version: 4.6

    Project link: https://github.com/udacity/ud851-Sunshine/tree/student/S02.02-Solution-Menus

    Could not find com.android.tools.build:aapt2:3.2.1-4818971**. Searched in the following locations:
        file:/C:/Users/sandeepk2/AppData/Local/Android/Sdk/extras/m2repository/com/android/tools/build/aapt2/3.2.1-4818971/aapt2-3.2.1-4818971.pom
        file:/C:/Users/sandeepk2/AppData/Local/Android/Sdk/extras/m2repository/com/android/tools/build/aapt2/3.2.1-4818971/aapt2-3.2.1-4818971-windows.jar
        file:/C:/Users/sandeepk2/AppData/Local/Android/Sdk/extras/google/m2repository/com/android/tools/build/aapt2/3.2.1-4818971/aapt2-3.2.1-4818971.pom
        file:/C:/Users/sandeepk2/AppData/Local/Android/Sdk/extras/google/m2repository/com/android/tools/build/aapt2/3.2.1-4818971/aapt2-3.2.1-4818971-windows.jar
        file:/C:/Users/sandeepk2/AppData/Local/Android/Sdk/extras/android/m2repository/com/android/tools/build/aapt2/3.2.1-4818971/aapt2-3.2.1-4818971.pom
        file:/C:/Users/sandeepk2/AppData/Local/Android/Sdk/extras/android/m2repository/com/android/tools/build/aapt2/3.2.1-4818971/aapt2-3.2.1-4818971-windows.jar
        https://jcenter.bintray.com/com/android/tools/build/aapt2/3.2.1-4818971/aapt2-3.2.1-4818971.pom
        https://jcenter.bintray.com/com/android/tools/build/aapt2/3.2.1-4818971/aapt2-3.2.1-4818971-windows.jar Required by:
        project :app
    

    How can I fix it?

  • Vicky T
    Vicky T over 5 years
    Thanks, this worked for me. I had to add 3 levels of directories. Also there are 3 flavors of the jar file. On a mac it is: dl.google.com/dl/android/maven2/com/android/tools/build/aapt‌​2/… (substitute osx or linux for windows in the jar file)
  • mike
    mike over 5 years
    Why Google is not bundling this in their repo? Android dev exp is the worst I had
  • lostomato
    lostomato over 5 years
    thanks, why is there jcenter() in my build.gradle? I add google() and it works.
  • Daniel
    Daniel over 5 years
    I had jcenter() and added google() afterwards to fix the error.
  • OneCricketeer
    OneCricketeer over 5 years
    @Daniel order doesn't matter too much, generally, but the Google libraries should be listed first since they are more important for building your apps
  • Meenohara
    Meenohara over 5 years
    Thank you for mentioning where exactly to add "google()"
  • Fatih TAN
    Fatih TAN over 5 years
    Excellent answer
  • Rodrigo Recio
    Rodrigo Recio over 5 years
    Ok, this really fixed it, but can someone explain why?
  • Lior
    Lior over 5 years
    may i ask, how in the world did you know about it? IOW,where can i learn such things, too?
  • nima
    nima about 5 years
    yes, this is the solution, after upgrading gradle, must resync all dependencies for run this command successfully: react-native run-android
  • Jeremy Caney
    Jeremy Caney almost 4 years
    Would you mind updating your answer with additional information? What differs in this configuration from other, previous answers? Do the previous approaches not work in Android Studio 3.6.3? What specific parts of your configuration are key to the solution? Is it primarily the maven {} configurations?
  • Abeni
    Abeni almost 4 years
    yes , other answers do not solve issues on the latest android studio update.