简体   繁体   English

Gradle无法解析Android Studio中的依赖项

[英]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. 我正在Android Studio上开发Android应用程序,有3个同事,最近,我们的项目不再构建了。 We all have different versions of Android Studio (mine is 0.2.8) and it fails to compile on all of them. 我们都有不同版本的Android Studio(我的是0.2.8)并且它无法在所有版本上进行编译。 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). 我们无法找到导致问题的原因,因为它发生在我们所有人的不同时刻(奇怪的是,使用相同的项目版本,应用程序是在我的Android Studio上而不是在我的同事之上)。

Sometimes, Android Studio is able to compile my project when it opens it, but then fails when I try to run the app. 有时,Android Studio能够在打开项目时编译我的项目,但在我尝试运行应用程序时失败。 But most of the time, Android Studio fails to compile my project when it opens it. 但大多数时候,Android Studio在打开它时无法编译我的项目。

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' . 我没有错误来帮助我理解这个问题,只有后台任务的消息标题可以给我一些发生的事情: 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. 我不知道它是否与build.gradle文件有关,但是在这里你可以找到错误的东西。

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? 解决依赖关系时Android Studio的作用是什么? What can cause it to hang like this? 是什么导致它像这样挂起?

EDIT: 编辑:

When executing gradle build --info , it gives me the following error : 执行gradle build --info ,它给出了以下错误:

FAILURE: Build failed with an exception. FAILURE:构建因异常而失败。

  • What went wrong: Execution failed for task ':compileDebug'. 出了什么问题:任务':compileDebug'执行失败。

    Cannot find System Java Compiler. 找不到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. 确保已安装JDK(而不仅仅是JRE)并将JAVA_HOME系统变量配置为指向相应目录。

EDIT 2: 编辑2:

Android Studio stopped being able to compile my project again. Android Studio再次无法编译我的项目。 Now it stops at Gradle: Resolve dependencies ':_ReleaseApk' . 现在它停在Gradle: Resolve dependencies ':_ReleaseApk' And when I try to compile with gradle via command line, it works without any error... 当我尝试使用gradle通过命令行编译时,它可以正常工作...

EDIT 3: 编辑3:

Again, Android Studio is failing at compiling my project. 同样,Android Studio无法编译我的项目。 Now it stops at Gradle: Resolve dependencies ':_DebugCompile' . 现在它在Gradle: Resolve dependencies ':_DebugCompile'停止。 And when I try to compile with gradle via command line, it works without any error... God I hate Gradle! 当我尝试使用gradle通过命令行编译时,它没有任何错误...上帝我讨厌Gradle!

After adding the JAVA_HOME variable, I was able to compile my application like usual. 添加JAVA_HOME变量后,我能像往常一样编译我的应用程序。

EDIT: 编辑:

After I got the another error (see EDIT 2 on the question), I just deleted the build folder of my project and it worked again. 在我收到另一个错误后(请参阅问题2上的EDIT 2),我刚刚删除了项目的build文件夹,它再次起作用。

EDIT 2: 编辑2:

It stopped working again (see EDIT 3 on the question) 它再次停止工作(请参阅编辑问题3)

I think that the problem you are hitting in Edit 3 is connected with those lines: 我认为您在编辑3中遇到的问题与这些行相关联:

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?!). 其中一些存储库不再处于活动状态,Android Studio在检查时没有超时(疯狂,对吧?!)。

This was my issue at least: Android Studio stuck on "Gradle: resolve dependancies '_debugCompile'" or 'detachedConfiguration1' 至少这是我的问题: Android Studio停留在“Gradle:resolve dependancies'_debugCompile'”或'detachedConfiguration1'

在我的情况下,其中一个开发人员没有在.gitignore文件中包含gradle.properties,这是卡住的原因

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM