Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gradle cannot resolve dependencies in Android Studio

I am developping an Android application on Android Studio with 3 collegues and recently, our project cannot be built anymore. We all have different versions of Android Studio (mine is 0.2.8) and it fails to compile on all of them. We aren't able to find what is causing the problem because it happened at different moments for all of us (strangely, with the same project version, the app was building on my Android Studio and not on the one of my collegues).

Sometimes, Android Studio is able to compile my project when it opens it, but then fails when I try to run the app. But most of the time, Android Studio fails to compile my project when it opens it.

I get no error to help me understand the problem, only the message title of the background task can give me a hint of what is happening : Gradle: Resolve dependencies ':_DebugApk'. This background task never finishes, it just load until the end of time.

I don't know if it is related to the build.gradle file, but here it is in case you can find something wrong.

home = System.getenv("ANDROID_HOME")

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.5.+'
    }
}
apply plugin: 'android'

repositories {
    mavenCentral()
    maven {
        url "http://maven.hq.couchbase.com/nexus/content/repositories/releases/"
    }

    maven {
        url "http://files.couchbase.com/maven2/"
    }
}

dependencies {
    compile 'com.android.support:support-v4:18.0.+'
    compile 'com.android.support:appcompat-v7:18.0.+'
    compile 'com.google.android.gms:play-services:3.1.36'
    compile fileTree(dir: 'libs', include: '*.jar')
    compile 'com.couchbase.cblite:CBLite:1.0.0-beta'
    compile 'com.couchbase.cblite:CBLiteEktorp:1.0.0-beta'
    compile 'com.couchbase.cblite:CBLiteJavascript:1.0.0-beta'

    instrumentTestCompile 'com.jayway.android.robotium:robotium-solo:4.3'
}

android {
    compileSdkVersion 18
    buildToolsVersion "18.1"

    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            resources.srcDirs = ['src']
            aidl.srcDirs = ['src']
            renderscript.srcDirs = ['src']
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']
        }

        // Move the tests to tests/java, tests/res, etc...
        instrumentTest.setRoot('tests')




        // Move the build types to build-types/<type>
        // For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
        // This moves them out of them default location under src/<type>/... which would
        // conflict with src/ being used by the main source set.
        // Adding new build types or product flavors should be accompanied
        // by a similar customization.
        debug.setRoot('build-types/debug')
        release.setRoot('build-types/release')
    }
}

tasks.withType(Compile) {
    options.encoding = 'UTF-8'
}

What is Android Studio doing when resolving dependencies? What can cause it to hang like this?

EDIT:

When executing gradle build --info, it gives me the following error :

FAILURE: Build failed with an exception.

  • What went wrong: Execution failed for task ':compileDebug'.

    Cannot find System Java Compiler. Ensure that you have installed a JDK (not just a JRE) and configured your JAVA_HOME system variable to point to the according directory.

EDIT 2:

Android Studio stopped being able to compile my project again. Now it stops at Gradle: Resolve dependencies ':_ReleaseApk'. And when I try to compile with gradle via command line, it works without any error...

EDIT 3:

Again, Android Studio is failing at compiling my project. Now it stops at Gradle: Resolve dependencies ':_DebugCompile'. And when I try to compile with gradle via command line, it works without any error... God I hate Gradle!

like image 614
Raphael Royer-Rivard Avatar asked Nov 26 '13 22:11

Raphael Royer-Rivard


People also ask

How do I resolve gradle dependencies?

Given a required dependency, with a version, Gradle attempts to resolve the dependency by searching for the module the dependency points at. Each repository is inspected in order. Depending on the type of repository, Gradle looks for metadata files describing the module ( .

How to add Gradle dependencies in Android Studio?

Go to File > Project Structure in Android Studio. Select the app module in the Modules list on the left. Select the Dependencies tab. Click the + button on the lower left to add the dependency.

How to include dependencies in Gradle?

To add a dependency to your project, specify a dependency configuration such as implementation in the dependencies block of your module's build.gradle file.

What does (*) mean in Gradle dependencies?

Dependencies with the same coordinates that can occur multiple times in the graph are omitted and indicated by an asterisk(*).


1 Answers

I think that the problem you are hitting in Edit 3 is connected with those lines:

maven {
    url "http://maven.hq.couchbase.com/nexus/content/repositories/releases/"
}

maven {
    url "http://files.couchbase.com/maven2/"
}

Some of those repositories is not active any more, and Android Studio has no timeout when checking that (freakin crazy, right?!).

This was my issue at least: Android Studio stuck on "Gradle: resolve dependancies '_debugCompile'" or 'detachedConfiguration1'

like image 63
Danail Avatar answered Sep 27 '22 23:09

Danail