Could not find com.android.tools.build:gradle:4.0.1 ( or any version )
Asked Answered
A

3

36

Error :

Could not find com.android.tools.build:gradle:4.0.1. Searched in the following locations:

https://jcenter.bintray.com/com/android/tools/build/gradle/4.0.1/gradle-4.0.1.pom https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/4.0.1/gradle-4.0.1.pom

Required by: project : Open File

*** looks like google() and jcenter() are not working as expected.***

I migrated from android studio 2.3.3 to 4.0.1 and this error happened.

what is my problem???? plz tell me if you need more information .

thank you for your answer :)

Aggravation answered 29/7, 2020 at 15:26 Comment(4)
Have you tried clearing your build directory and rebuilding the project from scratch?Emersed
yeah. that's not workAggravation
Please use mavenCentral() for dependencies repository entry, jcenter() will be deprecated developer.android.com/studio/build/jcenter-migrationLevon
Entering the 6 lines in my gradle.properties from this answer https://mcmap.net/q/88539/-could-not-find-com-android-tools-build-gradle-4-0-1-or-any-version by @Sadegh is what fixed it for me. I described it here: https://mcmap.net/q/89042/-failed-to-resolve-com-google-firebase-firebase-bom-31-0-0Garb
A
58

This solution may only work in Iran. If you know that's working out of Iran, please let others know.

Why would a proxy be necessary? There have been a number of technology-related sanctions against Iran.

Windows

go to -> File | Settings | Appearance & Behavior | System Settings | HTTP Proxy, and choose -> manual proxy configuration. set host name: fodev.org and set port number: 8118. now you must find gradle.properties file. that must be in: Windows: C:\Users\YOURUSERNAME.gradle\gradle.properties OR for Linux: ~/.gradle/gradle.properties . if it does't exist, create that yourself and copy this:

systemProp.http.proxyHost=fodev.org
systemProp.http.proxyPort=8118
systemProp.http.nonProxyHosts=*.jitpack.io, *.maven.org
systemProp.https.proxyHost=fodev.org
systemProp.https.proxyPort=8118
systemProp.https.nonProxyHosts=*.jitpack.io, *.maven.org

Mac

Open Network settings by  > System Preferences > Network. Then, choose your wifi and click on advanced, which is located on bottom-right of the panel (if there’s a lock at the bottom left of the Network pane, click it to unlock the preference pane). A window would open in which you should go under "Proxies" tab and then check the box for "Web Proxy (HTTP)". There is a textfield named "Web Proxy Server" in which you should set it to fodev.org and in the next textfield you can enter the port number which is 8118 in this case. The steps may vary depending on the version of macOS and more information about procy server settings can be found on Apple Support Guide. You can also take a look at the screenshot.

macOS proxy settings

The last step is to make sure that have gradle.properties. On finder, choose Go > Go to Folder and then paste ~/.gradle/ and go (alternatively, you can trigger this menu by holding shift + command + G). If you don't see anyfile under the name ofgradle.properties, create it with textedit or terminal and paste this code there:

systemProp.http.proxyHost=fodev.org
systemProp.http.proxyPort=8118
systemProp.http.nonProxyHosts=*.jitpack.io, *.maven.org
systemProp.https.proxyHost=fodev.org
systemProp.https.proxyPort=8118
systemProp.https.nonProxyHosts=*.jitpack.io, *.maven.org

Now, you can run your project.

IMPORTANT : After installation of build.gradle 4.0.1 (or any version), restore this settings to previous state and remove the codes.

Aggravation answered 3/8, 2020 at 18:53 Comment(8)
thank you man, it took me a week to solve this. cant we use psiphon instead?Tiannatiara
@Tiannatiara you are welcome. I don't think so. vpn not working and we must use proxy.Aggravation
It used to work with proxy or VPN, but it can't sync anymore. I suggest this solution: #50291789Natica
@Natica It's ok for me and there is no problem with sync. i 've been using it for monthsAggravation
The best solution ever, I live in Syria and suffer from gradle sync ban, nothing worked with me but your solution, you deserve 10 upvotesKonikow
Some companies may use WAF solutions and this may cause a problem retrieving certain URLs from the repositories. You may need to use a proxy/VPN or add the WAF certificate into your Android Studio's cacert file (the only caveat: you need to set the modified cacert file's timestamp the same as the original, otherwise Android Studio will complain; another issue you need to do this for every Android Studio update).Levon
thanks Sadegh. my problem was resolved with your help :) Thank youSuspensory
I was stuck with an issue for 2 days. I updated my Firebase BoM and the dependencies were no longer recognized. Upon further research the issue was: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target. Once I added the 6 lines in my gradle.properties file, everything worked. THANK YOU!!!Garb
C
3

Deleting and reinstalling my node modules seemed to work for me

rm -rf node_modules
yarn install
Counterattraction answered 18/2, 2021 at 22:51 Comment(0)
S
-2

If you are importing a project from github or other.

  1. Close the project in Android Studio. File -> Close project.
  2. In file explorer, delete .idea, .gradle and gradle if there are any inside your project folder. (.idea, .gradle are hidden items. Make sure hidden items are shown in your file explorer) or if you are using command line, do ls -a
  3. Open the project in Android Studio again.
  4. Done.
Seasonseasonable answered 25/4, 2021 at 5:42 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.