51

I was following a tutorial to develop icon pack for android and when I imported the project I got several errors and it was solved here - Gradle Version 4.6 - Absolute path are not supported when setting an output file name

After solving that error, the following error poped up.

Could not find com.android.tools.build:aapt2:3.2.0-4818971.
Searched in the following locations:

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

file:/C:/Users/Tomin Jacob/AppData/Local/Android/Sdk/extras/m2repository/com/android/tools/build/aapt2/3.2.0-4818971/aapt2-3.2.0-4818971-windows.jar

file:/C:/Users/Tomin Jacob/AppData/Local/Android/Sdk/extras/google/m2repository/com/android/tools/build/aapt2/3.2.0-4818971/aapt2-3.2.0-4818971.pom

file:/C:/Users/Tomin Jacob/AppData/Local/Android/Sdk/extras/google/m2repository/com/android/tools/build/aapt2/3.2.0-4818971/aapt2-3.2.0-4818971-windows.jar

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

file:/C:/Users/Tomin Jacob/AppData/Local/Android/Sdk/extras/android/m2repository/com/android/tools/build/aapt2/3.2.0-4818971/aapt2-3.2.0-4818971-windows.jar

https://jcenter.bintray.com/com/android/tools/build/aapt2/3.2.0-4818971/aapt2-3.2.0-4818971.pom

https://jcenter.bintray.com/com/android/tools/build/aapt2/3.2.0-4818971/aapt2-3.2.0-4818971-windows.jar

https://jitpack.io/com/android/tools/build/aapt2/3.2.0-4818971/aapt2-3.2.0-4818971.pom

https://jitpack.io/com/android/tools/build/aapt2/3.2.0-4818971/aapt2-3.2.0-4818971-windows.jar
Required by:
    project :licensing

I tried to open the URLs and I was able to download JAR (aapt2-3.2.0-4818971-windows.jar) and JSON (aapt2-3.2.0-4818971.pom.json) files from the first 2 URLs. Should I copy these files somewhere? What should I do to solve this error?

Spangen
  • 4,420
  • 5
  • 37
  • 42
TomJ
  • 1,803
  • 14
  • 37
  • 57

6 Answers6

125

Most likely you do not have the Google repository in your project's build.gradle file. Add google() in BOTH locations as shown below:

buildscript {

    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.0'
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}
shagberg
  • 2,427
  • 1
  • 12
  • 23
  • 4
    I am still getting the same error even after adding google() in the build.gradle file. – TomJ Sep 28 '18 at 02:00
  • @TomJ Did you add `google()' in BOTH of the spots above? Notice that it is present in two locations... – shagberg Sep 28 '18 at 21:23
  • 1
    Looks like a gradle upgrade to 4.6 misses `google()` in ``allprojects { /** */ }`` section. This works! – Dut A. Dec 21 '18 at 02:57
  • Perfect Solution...Thanks... BTW...where you found this type of solution.. :D – Neo Apr 22 '19 at 10:01
  • 1
    @Neo You know, at this point I don't recall how I became aware of this solution. Probably trial and error. – shagberg Apr 22 '19 at 13:42
9

I was able to solve the issue by adding google() in both locations:

File -> Project Structure -> Project -> *Now add ", google()" in

Android Plugin Repository

and

Default Library Repository

*

eurydice
  • 91
  • 2
8

When you upgrade to 4.6 version of gradle. You need following upgrades too. Gradle Plugin Release page.

1. Android Studio 3.+

You need Android Studio version 3.+ to have 4.6 version of gradle. At the time of post latest release was 3.2.1. You can see latest release on this page.

2. Gradle Plugin 3.1.+

You need 3.1.+ gradle plugin for gradle-4.6 support. Check in project level build.gradle.

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

At the time of post latest version was 3.2.1. You can see latest release here.

3. Add Google Maven Library

You need to add Google Maven library to project level build.gradle like below code.

buildscript {
    repositories {
        google()
        ...
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.1'
        ...
    }
}

allprojects {
    repositories {
        google()
        ...
    }
}
Community
  • 1
  • 1
Khemraj Sharma
  • 57,232
  • 27
  • 203
  • 212
1

see the dependencies of module :licensing and use com.android.tools.build:aapt2:3.2.0 (or even "com.android.tools.build:aapt2:3.2.0:windows") there, which is the final version ...that 4818971 version should ordinary come with an alpha prefix/suffix (the version number seems to be incorrect). maybe adding repository google() might be required, too. ordinary, that dependency should be present; removing that dependency might be another possible option.

Martin Zeitler
  • 1
  • 19
  • 155
  • 216
  • Can you elaborate it a little more? I am a newbie to android, so I will be a little bit disturbing to you. – TomJ Sep 27 '18 at 17:23
  • @TomJ just yesterday updated the same dependency: https://github.com/google/bundletool/compare/master...syslogic:master#diff-c197962302397baf3a4cc36463dce5ea – Martin Zeitler Sep 27 '18 at 19:19
1

For those people who still face exactly the same problem even after adding two google to BOTH positions in relevant gradle file.I would suggest you to check Android Studio -> Preferences -> HTTP Proxy page.
If you find it says some warnings like "...have set JVM proxy to 127.0.0.1".Then you should consider vpn-related issues which depends on your context.
If your desktop is MacOS, then go to Network setting page, advance->proxy tab,uncheck all the checkbox there.
Back to your IDE as following steps: Android Studio->File->Invalidate Caches/Restart.After that,go back to check Android Studio -> Preferences -> HTTP Proxy page again,previous warnings should be gone.Run again.

zionpi
  • 2,593
  • 27
  • 38
0

I solved my issue by upgrading my classpath from

    'com.google.gms:google-services:4.0.0

to

    'com.google.gms:google-services:4.2.0'

hope this helps