【问题标题】:Gradle cannot resolve dependencies in Android StudioGradle 无法解析 Android Studio 中的依赖项
【发布时间】:2013-12-12 07:41:58
【问题描述】:

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

有时,Android Studio 能够在打开我的项目时对其进行编译,但在我尝试运行该应用程序时却失败了。但大多数情况下,Android Studio 在打开我的项目时无法编译它。

我没有收到任何错误来帮助我理解问题,只有后台任务的消息标题可以给我一个提示:Gradle: Resolve dependencies ':_DebugApk'。这个后台任务永远不会完成,它只会加载到时间结束。

不知道是不是和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'
}

解决依赖关系时,Android Studio 在做什么?什么会导致它这样挂起?

编辑:

执行gradle build --info 时,出现以下错误:

FAILURE:构建失败并出现异常。

  • 出了什么问题:任务 ':compileDebug' 执行失败。

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

编辑 2:

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

编辑 3:

同样,Android Studio 无法编译我的项目。现在它停在Gradle: Resolve dependencies ':_DebugCompile'。当我尝试通过命令行使用 gradle 进行编译时,它可以正常工作......上帝我讨厌 Gradle!

【问题讨论】:

  • 你能通过 gradle 从命令行构建它吗,我不认为这是一个 android studio 问题。尝试运行 gradle build --info
  • 我在帖子中添加了结果
  • 遇到与上一个相同的错误。它只是卡在那里。开始认为 Android Studio 太年轻了,不值得努力......

标签: android gradle android-studio


【解决方案1】:

我认为您在 Edit 3 中遇到的问题与以下几行有关:

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

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

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

这至少是我的问题: Android Studio stuck on "Gradle: resolve dependancies '_debugCompile'" or 'detachedConfiguration1'

【讨论】:

    【解决方案2】:

    添加 JAVA_HOME 变量后,我能够像往常一样编译我的应用程序。

    编辑:

    在我收到另一个错误后(请参阅问题的 EDIT 2),我刚刚删除了我的项目的 build 文件夹,它又可以工作了。

    编辑 2:

    它再次停止工作(请参阅问题编辑 3)

    【讨论】:

      【解决方案3】:

      就我而言,其中一位开发人员没有在 .gitignore 文件中包含 gradle.properties,这是卡住的原因

      【讨论】:

        猜你喜欢
        • 2015-12-19
        • 1970-01-01
        • 2019-03-31
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-02-23
        • 2019-06-08
        相关资源
        最近更新 更多