Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Could not resolve com.android.tools.build:gradle:2.2.3

I'm working on a mobile app project for work, but often when I attempt to run the application it gives me the following error:

Error:A problem occurred configuring root project 'projectName'. Could not resolve all dependencies for configuration ':classpath'. Could not resolve com.android.tools.build:gradle:2.2.3. Required by: :projectName:unspecified No cached version of com.android.tools.build:gradle:2.2.3 available for offline mode.

I have tried a number of different things including deselecting the Offline work checkbox in the settings and then closing and re-opening Android Studio, but nothing seems to fix the issue. It may build fine for a few times in a row, but that same error keeps popping up. Then I have to try variations of building and making the app, or exiting and re-opening Android Studios. Nothing consistently works though. Any insight into what may be causing this issue and how it can be fixed would be appreciated.

***Update: Upon request I have added below my app gradle content

apply plugin: 'com.android.application'

android {
compileSdkVersion 24
buildToolsVersion "24.0.1"
useLibrary 'org.apache.http.legacy'

dexOptions {
    javaMaxHeapSize "8g"
}

defaultConfig {
    applicationId "com.example"
    minSdkVersion 15
    targetSdkVersion 24
    versionCode 1
    versionName "1.0"

    multiDexEnabled true
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
    debug{ 
        debuggable true
    }
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:24.2.1'
compile 'com.android.support:design:24.2.1'
compile 'com.google.android.gms:play-services:9.4.0'
compile 'com.android.support:recyclerview-v7:24.2.1'
compile 'com.android.support:support-v4:24.2.1'

compile files('libs/gson-2.2.2.jar')
compile group: 'cz.msebera.android' , name: 'httpclient', version: '4.4.1.1'
compile 'com.facebook.stetho:stetho:1.3.1'
compile 'com.loopj.android:android-async-http:1.4.9'
}
like image 515
Deus Ex Machina Avatar asked Feb 22 '17 22:02

Deus Ex Machina


People also ask

Why isn't my Gradle connection working?

Please check your gradle's proxy settings. Enable it or disable it in the following file: If your connection to repositories is not stable, use a proxy instead of direct connection. If you used to use a proxy for gradle, check if it is still working.

Where is the Android Gradle plugin in Maven Central?

It seems the current versions of the Android Gradle plugin are not added to Maven Central, but they are present on jcenter. Add jcenter()to your list of repositories and Gradle should find version 2.2.3.

Why do I need a proxy for Gradle?

If your connection to repositories is not stable, use a proxy instead of direct connection. If you used to use a proxy for gradle, check if it is still working. Thanks for contributing an answer to Stack Overflow!

Is there a Gradle bin path in system variables?

One thing that I was missing was the gradle bin path in my System Variables. I had it only in my user variable PATH. Downloading gradle 4.10 and adding the same to System Environment Variable PATH did it for me.


1 Answers

It turns out the solution to my particular issue was relatively simple. The error message was a bit deceiving as this was not a problem with the offline mode switch, but rather confusion with the gradle file. Here are a few steps I took to fix the issue:

  1. For Android Studio 2.3 go to File>Settings>Gradle and select the "Use default gradle wrapper" option. Also make sure the checkbox next to "Offline work" is unchecked just in case.
  2. Click the "Apply" button
  3. Within the build.gradle file (the one named after your project) under the "Gradle Scripts" section of Android Studio make certain that your current build gradle class path matches the current version of Android Studio. An example for Android Studio 2.3:

    buildscript {
        repositories {
        jcenter()
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:2.3.0'
        }
    }
    
  4. Also within the Gradle Scripts section make sure that your gradle-wrapper.properties file is referencing the correct gradle file in the distribution URL. For example for gradle 3.3:

    distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
    
  5. Navigate to C:\Program Files\Android\Android Studio\gradle and ensure there is a gradle folder with the same name as the gradle you are using. In my case I ensured there is a folder named gradle-3.3 with a zip file named gradle-3.3-all.zip. It is relatively easy to find this zip file online.

  6. Delete the .gradle folder in C:\Users\yourUser with yourUser being whichever user your Android Studio project is under.
  7. Close Android Studio and restart. It should begin the gradle sync process and rebuild the .gradle file.

For me when I did this it also complained about not finding the gradle-3.3-all.zip file in the .gradle folder. I was able to fix this by adding the gradle-3.3-all.zip file to C:\Users\yourUser.gradle\wrapper\dists\gradle-3.3-all\55gk2rcmfc6p2dg9u9ohc3hw9. I'm not sure if the folder has the same name for everyone, but whatever the name, that is the location I went to. If all this doesn't work I would try a variation of these steps, and hopefully it works for you.

like image 101
Deus Ex Machina Avatar answered Oct 12 '22 09:10

Deus Ex Machina