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

标签 android gradle android-studio

我正在和 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: 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.

编辑 2:

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

编辑 3:

同样,Android Studio 无法编译我的项目。现在它停止在 Gradle: Resolve dependencies ':_DebugCompile'。当我尝试通过命令行使用 gradle 进行编译时,它没有任何错误地工作......天哪,我讨厌 Gradle!

最佳答案

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

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

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

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

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

关于android - Gradle 无法解析 Android Studio 中的依赖项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20229355/

相关文章:

android - BottomSheetDialogFragment暴露的高度

android - 我的 Android 应用无法识别 R.string 资源 - 可能是什么原因?

android - list 合并失败

gradle - 从Gradle构建脚本使用插件Java API

Android Studio 布局 : Trying to make button 50% width and 50% height,,中间有按钮

android - Android Studio 中不支持的类型 'add-resource'

android - android 中的 Flash(不是 webview 中的)

java - maven central 是否希望共享源 URL?

java - 当用户退出应用程序/终止进程时,是否可以在 android 中执行脚本?

android-studio - 如何在 Gradle 中添加 Android Studio 插件作为依赖项?