88

After I update Android Studio to 3.2.1 and gradle version in my project I am getting following build error.

I have already checked lots of questions related this question but no luck.

Project dependency Build.gradle

buildscript {

    repositories {
        google()
        mavenCentral()
        maven { url 'https://maven.google.com' }
        gradlePluginPortal()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.1'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        maven { url "https://jitpack.io" }
        jcenter ()

    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

Error

org.gradle.api.ProjectConfigurationException: A problem occurred configuring root project 'DemoAppppp'.
    at org.gradle.configuration.project.LifecycleProjectEvaluator.addConfigurationFailure(LifecycleProjectEvaluator.java:94)

Caused by: org.gradle.api.internal.artifacts.ivyservice.DefaultLenientConfiguration$ArtifactResolveException: Could not resolve all artifacts for configuration ':classpath'.
    at org.gradle.api.internal.artifacts.configurations.DefaultConfiguration.rethrowFailure(DefaultConfiguration.java:944)

Caused by: org.gradle.internal.resolve.ModuleVersionResolveException: Could not resolve com.android.tools.build:gradle:3.2.1.
Required by:
    project :
    at org.gradle.api.internal.artifacts.ivyservice.ivyresolve.RepositoryChainComponentMetaDataResolver.resolveModule(RepositoryChainComponentMetaDataResolver.java:103)
    at org.gradle.api.internal.artifacts.ivyservice.ivyresolve.RepositoryChainComponentMetaDataResolver.resolve(RepositoryChainComponentMetaDataResolver.java:63)

Caused by: org.gradle.internal.resolve.ModuleVersionResolveException: Could not resolve com.android.tools.build:gradle:3.2.1.
    at org.gradle.api.internal.artifacts.ivyservice.ivyresolve.ErrorHandlingModuleComponentRepository$ErrorHandlingModuleComponentRepositoryAccess.resolveComponentMetaData(ErrorHandlingModuleComponentRepository.java:139)

Caused by: org.gradle.api.resources.ResourceException: Could not get resource 'https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/3.2.1/gradle-3.2.1.pom'.
    at org.gradle.internal.resource.ResourceExceptions.failure(ResourceExceptions.java:74)
    at org.gradle.internal.resource.ResourceExceptions.getFailed(ResourceExceptions.java:57)

Caused by: org.gradle.internal.resource.transport.http.HttpRequestException: Could not GET 'https://dl.google.com/dl/android/maven2/com/android/tools/build/gradle/3.2.1/gradle-3.2.1.pom'.
    at org.gradle.internal.resource.transport.http.HttpClientHelper.performRequest(HttpClientHelper.java:96)

Caused by: org.apache.http.conn.HttpHostConnectException: Connect to localhost:80 [localhost/127.0.0.1, localhost/0:0:0:0:0:0:0:1] failed: Connection refused: connect 
Caused by: java.net.ConnectException: Connection refused: connect 

Update

I just followed @CoolMind answer it solve the gradle issue, but there is another issue comes which is This

And I followed those answers which is given in this question but not solve my problem

Vikas singh
  • 3,461
  • 3
  • 14
  • 28

23 Answers23

122

Just turn off the Toggle Offline Mode .

On the top right side of the Window .

Click on Gradle 2nd number option(just near of Setting option) click on it then you will be able to do work continuously.

As you can see the image

enter image description here

Vikas singh
  • 3,461
  • 3
  • 14
  • 28
  • thanks.i faced this issue due to internet connectivity and gradle went offline mode. now after changing it back to onlilne its working fine – Jasbin Karki May 13 '20 at 03:37
  • 3
    It is hard to tell whether you are in 'offline' or not offline mode. I think having the little interrupted horizontal bar means offline. Having a gray box around the bar means not-offline -- ie online. Having the tool tip just say toggle offline doesn't help. Seeing it in a dark theme is hard too. – Ribo May 20 '20 at 22:04
  • 1
    Doesn't work! The Twitter SDK is giving this error – tpbafk Nov 29 '21 at 06:50
  • Thanks a million, this just resolved it, never knew my offline mode was turned on – Peter Akwa Mar 09 '22 at 08:54
  • 11
    Doesn't work for me. Toggling offline mode makes no difference whatsoever. I think you should take out the 100% solution part! – gignu May 16 '22 at 17:39
  • @gignu then may be you have different problem – Vikas singh May 17 '22 at 09:46
  • 4
    @Vikassingh no, I get exactly the same error message as in the title of this question. The solution in my case was to upgrade my FLIPPER_VERSION in my gradle.properties file which was outdated. Once I did that, the error was gone and the build succeeded. If you're interested and want to reproduce it, change your FLIPPER_VERSION to 0.52.1 and you should get the same build error as in the title of this question. – gignu May 17 '22 at 15:59
33

In The Right Side of the Android Studio, You can See Gradle option just click it and you will see a screen which is given below.

Gradle can be offline. If offline, you should do it online.

Screenshot

33

In my case, I have added a dependency which is not available in any of the cloud repositpories. On removing dependency,it started working

Tarun Anchala
  • 2,232
  • 16
  • 15
11

You might have added a dependency not available in the repository

wilfred
  • 139
  • 1
  • 4
  • 1
    This. The real issue was one step above in the error tree, not the error from the title of this post. – George Mar 18 '23 at 22:47
7

Check the below points.

  1. Internet connectivity issue.
  2. Toggle Offline Mode.

enter image description here

Tippu Fisal Sheriff
  • 2,177
  • 11
  • 19
3

I had this problem also. Tried all the suggestions, but didnt help. The problem was in offline/online mode as other stated but you have to also check the compiler settings. Make sure there is no --offline flag

Preferences -> Build, Execution, Deployment -> Compiler

( Menubar 'File' button, 'Settings' menu option, 'Build, Execution, Deployment' menu twisty, 'Compiler' submenu )

On Command-line Options: --stacktrace

not

--offline --stacktrace

Ribo
  • 3,363
  • 1
  • 29
  • 35
Lorensius W. L. T
  • 1,734
  • 4
  • 19
  • 31
2

Opening the "Gradle" side panel, and toggling the "online/offline" button to "online" worked for me as well.

Previous failed solution: I searched on Gradle's website for a manual download of version 3.6.3, but there wasn't one. That number is the same version, however, of Android Studio being used.

TheJarvis
  • 21
  • 2
1

This problem appeared on OS X. After disabling web filtering application (some Google IPs were blocked) it disappeared. After syncing with gradle all files have been downloaded.

Also you may set a checkbox like in https://discuss.gradle.org/t/android-studio-could-not-get-resource-https-dl-google-com-dl-android-maven2-com-android-tools-build-gradle-3-1-0-gradle-3-1-0-pom/26734:

Settings -> Build … -> Gradle -> Android Studio -> Enable embedded maven repository.

See also Could not resolve com.android.tools.build.gradle:3.0.1.

CoolMind
  • 26,736
  • 15
  • 188
  • 224
  • Thank you for your answer. It solves the gradle issue, but there is one more problem occurs which is [this](https://stackoverflow.com/questions/51218535/unable-to-resolve-dependency-for-appdebug-compileclasspath-could-not-resolv). – Vikas singh Jan 06 '19 at 08:14
  • and I just follows those answers which is given in that question but no luck – Vikas singh Jan 06 '19 at 08:16
  • @vikassingh, sorry, but I don't know, how to help in your case. – CoolMind Jan 10 '19 at 11:03
1

If you have updated Gradle then most likely you will get this error because Gradle will be offline by default after updating.

Solution:

In right hand side top corner click Gradle (Gradle panel or Gradle window opens). Connect Gradle to the internet by clicking the icon at the top of Gradle panel or window.

Cronay
  • 4,875
  • 3
  • 13
  • 18
1

This problem occurs when your android studio is not getting internet connection. You fix the internet, the problem fixes by itself. To confirm the internet issue of the android studio you can attempt to login, update, connecting to firebase, etc all will fail.

1

For me, the issue was organization's Artifactory password got changed needed to update Gradle with new credentials.

Ebin Joy
  • 2,690
  • 5
  • 26
  • 39
1

upgrade project to androidx change compile to implementation change v4 or v7 to androidx dependencies

  • 2
    As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Mar 16 '22 at 16:38
1

My problem was because a version was wrong in the dependencies in build.gradle (app). If you have internet, it might be because of this, so try finding other warnings that might indicate a wrong dependency.

Jack'
  • 1,722
  • 1
  • 19
  • 27
1

Mostly, there is always a dependency that you might have added that doesn't exit, so you have to find and delete it. This worked for me.

0

Just you have to turn on the Toggle button, come in the grade menu at the right side of the window... So you going to online mode.. you must have internet connection for.. build grade.. otherwise it's again show you same error or other types of error...

0

I also have been having the same error since when i updated my Android studio and even with a fast internet network am unable to start a new project but today I discover a solution just click o your event log and update any suggested plugin that shows up and rebuild your project, then your have your project working well and fine it worked for me trust it to work for you also .

Eazy
  • 31
  • 1
  • Welcome to StackOverflow, add some more description and code if it's required to understand the answer because it will resolve someone's else problem ASAP. – Nensi Kasundra May 13 '20 at 04:23
0

This Works 100%

turn off the Toggle Offline Mode .

Check the image below

enter image description here

Rehan Khan
  • 1,031
  • 13
  • 10
0

This error may arrises due to "android:exported="false"". please make sure when to use "android:exported="true/false"".

0

In my case none of the above helped. I had to upgrade my FLIPPER_VERSION in my gradle.properties file. You can find the latest FLIPPER_VERSION here: https://github.com/facebook/flipper/releases

gignu
  • 1,763
  • 1
  • 14
  • 24
0

Deleting my .gradle file ("C:\Users<userName>.gradle") and going to the device manager and running "Cold Boot Now" fixed this problem for me

brando f
  • 311
  • 2
  • 9
0

Try to Toggle Offline Mode, if not worked check your flipper version if it is old try to update it(worked for me). Upgrading flipper version in gradle.properties

From

FLIPPER_VERSION=0.39.0

To

FLIPPER_VERSION=0.99.0
Pawan Verma
  • 1,152
  • 14
  • 22
0

In my case I added maven repository in both repository section , so this issue occurs, So I removed this line from above repotories section inside buildscript for reference visit this answer https://stackoverflow.com/a/75005827/12748481

0

i faced this issue after adding

implementation("com.squareup.okhttp3:okhttp:3.1.0")

i removed it and issue resolved.

moral of the story:
remove older implementations if (another resource already has newer classes)
also check internet connection.

sifr_dot_in
  • 3,153
  • 2
  • 33
  • 42