Gradle 无法解析 Android Studio 中的依赖项 [英] Gradle cannot resolve dependencies in Android Studio

查看:41
本文介绍了Gradle 无法解析 Android Studio 中的依赖项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在与 3 位同事在 Android Studio 上开发一个 Android 应用程序,最近,我们的项目无法再构建.我们都有不同版本的 Android Studio(我的是 0.2.8)并且它无法在所有版本上编译.我们无法找到导致问题的原因,因为它发生在我们所有人的不同时刻(奇怪的是,使用相同的项目版本,该应用程序是在我的 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).

有时,Android Studio 可以在打开我的项目时编译它,但是当我尝试运行该应用程序时会失败.但大多数情况下,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. But most of the time, Android Studio fails to compile my project when it opens it.

我没有得到任何错误来帮助我理解问题,只有后台任务的消息标题可以提示我正在发生的事情:Gradle: Resolve dependencies ':_DebugApk'.这个后台任务永远不会完成,它只是加载到时间结束.

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.

我不知道它是否与 build.gradle 文件有关,但在这里是为了防止您发现错误.

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'
}

Android Studio 在解析依赖项时在做什么?什么会导致它像这样挂起?

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

在执行 gradle build --info 时,它给了我以下错误:

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

FAILURE:构建失败,出现异常.

FAILURE: Build failed with an exception.

  • 出了什么问题:任务:compileDebug"的执行失败.

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

      找不到系统 Java 编译器.确保您已安装 JDK(不仅仅是 JRE)并将您的 JAVA_HOME 系统变量配置为指向相应的目录.

    • 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.

      编辑 2:

      Android Studio 无法再次编译我的项目.现在它停在 Gradle: Resolve dependencies ':_ReleaseApk'.当我尝试通过命令行使用 gradle 进行编译时,它可以正常工作而没有任何错误...

      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...

      编辑 3:

      再说一次,Android Studio 无法编译我的项目.现在它停在 Gradle: Resolve dependencies ':_DebugCompile'.当我尝试通过命令行使用 gradle 进行编译时,它可以正常工作而没有任何错误...上帝,我讨厌 Gradle!

      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!

      推荐答案

      我认为您在 Edit 3 中遇到的问题与这些行有关:

      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/"
      }
      

      其中一些存储库不再处于活动状态,并且 Android Studio 在检查时没有超时(非常疯狂,对吧?!).

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

      这至少是我的问题:Android Studio 卡在Gradle:解析依赖关系"_debugCompile'"或分离配置1"

      这篇关于Gradle 无法解析 Android Studio 中的依赖项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆