Android Studio 卡在“Gradle:解决依赖项 '_debugCompile'”或“detachedConfiguration1”上

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23837465/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 07:30:54  来源:igfitidea点击:

Android Studio stuck on "Gradle: resolve dependencies '_debugCompile'" or 'detachedConfiguration1'

androidandroid-studio

提问by Danail

I have no idea what I changed in my project, but it suddenly cannot get past this step while building gradle scripts.

我不知道我在项目中做了什么更改,但是在构建 gradle 脚本时突然无法通过这一步。

There is no problem building it with just 'gradle assemble'.

仅使用“gradle assemble”构建它没有问题。

EDIT: the previous stuck point was resolve dependencies 'detachedConfiguration1'. (After the first failed attempt of _debugCompile, I'm back at detachedConfiguration1). I guess it is too many dependency projects? Some sample projects I have are imported just fine in the Studio.... I reinstalled the Android Studio and removed all the settings and preferences as well.

编辑:之前的卡点是解决依赖关系“detachedConfiguration1”。(在 _debugCompile 第一次尝试失败后,我又回到了 detachedConfiguration1)。我猜是依赖项目太多了?我的一些示例项目在 Studio 中导入得很好......我重新安装了 Android Studio 并删除了所有设置和首选项。

I have to kill it every time it starts doing this.

每次它开始这样做时,我都必须杀死它。

Ring any bells?

敲钟吗?

import com.android.build.gradle.AppPlugin
import com.android.build.gradle.LibraryPlugin

// Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript {
repositories {
    mavenCentral()
}

dependencies {
    classpath 'com.android.tools.build:gradle:0.9.+'
}

apply plugin: 'android'

repositories {
    maven { url 'http://ksoap2-android.googlecode.com/svn/m2-repo' }

    mavenCentral()
}

dependencies {

    compile 'com.google.code.ksoap2-android:ksoap2-android:2.5.2'
    compile 'com.android.support:support-v4:18.0.+'
    compile fileTree(dir: 'libs', include: '*.jar')
    compile project(':lib-projects:StickyListHeaders')
    compile project(':lib-projects:ActionBar-PullToRefresh')
    compile project(':lib-projects:facebook')
    compile project(':lib-projects:Mopub:mopub-sdk')
    compile project(':lib-projects:NineOldAndroids')
    compile project(':lib-projects:ActionBarSherlock:actionbarsherlock')
    compile project(':lib-projects:ActionBarSherlock:actionbarsherlock-i18n')
    compile project(':lib-projects:SmoothProgressBar')
    compile project(':lib-projects:android-viewflow-master:viewflow')
}

android {

    signingConfigs {

        debug {
            storeFile file('....')
        }
    }

    compileSdkVersion 19
    buildToolsVersion "19.0.3"
    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')

    }
}

采纳答案by SBerg413

I've encountered this problem far too frequently since i switched over to Android Studio. This is indeed an issue with the repository not being accessible - either due to a network issue or, more likely, the repo being down for whatever reason.

自从我切换到 Android Studio 以来,我经常遇到这个问题。这确实是一个无法访问存储库的问题 - 要么是由于网络问题,要么更可能是由于任何原因存储库关闭。

The simplest work-around that I've found is to just select the "work offline" mode within the Android Studio preferences. This doesn't help if you need to add a new dependency, but if you already have all your dependencies added it does the trick.

我发现的最简单的解决方法是在 Android Studio 首选项中选择“离线工作”模式。如果您需要添加新的依赖项,这无济于事,但如果您已经添加了所有依赖项,它就可以解决问题。

To enable this setting go to:

要启用此设置,请转到:

Preferences -> Gradle

首选项 -> Gradle

In the right side options go down to "Global Gradel Settings" and check the "Offline work" box.

在右侧选项中,转到“全局分级设置”并选中“离线工作”框。

The box should look like:

该框应如下所示:

enter image description here

在此处输入图片说明

You can periodically uncheck this box to see if the repo is back online.

您可以定期取消选中此框以查看存储库是否重新上线。

NOTE: This option is the equivalent of setting the --offline flag when running a gradle build from the command line.

注意:此选项等效于从命令行运行 gradle 构建时设置 --offline 标志。

回答by Danail

It turns out that this line:

事实证明,这一行:

repositories {     
  maven {     
    url 'http://ksoap2-android.googlecode.com/svn/m2-repo'    
  }

is solely responsible for forever-stuck Android studio. Probably the repository is not active/offline today...

全权负责永远陷入困境的 Android 工作室。可能存储库今天不活动/离线......

Interesting questions:

有趣的问题:

  1. How come the gradle scripts work just fine in Terminal? (though it seemed slower than usual).

  2. How come THERE IS NO TIMEOUT for that? It surely created a few white hairs today.. ;)

  1. gradle 脚本如何在终端中正常工作?(虽然它似乎比平时慢)。

  2. 为什么没有超时?它今天肯定会产生一些白发..;)

回答by lm2a

Please run gradle from command line (opening a terminal in your project folder) using -info and check where it stop. I was experiencing something similar and it was related with jcenter(), because it can't reach a resource:

请使用 -info 从命令行运行 gradle(在您的项目文件夹中打开一个终端)并检查它在哪里停止。我遇到了类似的事情,它与 jcenter() 相关,因为它无法访问资源:

Resource missing. HTTP GET

资源丢失。获取

so, changing jcenter()by mavenCentral()in MyProject/build.gradledid the trick.

因此,改变jcenter()mavenCentral()MyProject/build.gradle做的伎俩。

I hope it can help.

我希望它能有所帮助。

回答by cahmazndnr

I encountered the same issue and resolved it by adding both http and https proxies in the gradle.properties file. It is important to add the https proxy as the gradle-2.10-all.zip is read using https:

我遇到了同样的问题并通过在 gradle.properties 文件中添加 http 和 https 代理来解决它。添加 https 代理很重要,因为 gradle-2.10-all.zip 是使用 https 读取的:

https://services.gradle.org/distributions/gradle-2.10-all.zip

https://services.gradle.org/distributions/gradle-2.10-all.zip

gradle.properties:

gradle.properties:

systemProp.http.proxyHost=<http proxy name>
systemProp.http.proxyPort=<http proxy port>
systemProp.https.proxyHost=<https proxy name>
systemProp.https.proxyPort=<https proxy port>

回答by Omid Raha

On the Debian,

Debian,

I have the same problem, fixed for me with two changes,

我有同样的问题,通过两个更改为我修复,

First enable proxy for gradle on the gradle.propertiesfile, both for httpand https:

首先在gradle.properties文件上为 gradle 启用代理,包括httphttps

systemProp.http.proxyHost=127.0.0.1
systemProp.http.proxyPort=8080
systemProp.https.proxyHost=127.0.0.1
systemProp.https.proxyPort=8080

And then next by installing lib32stdc++6and lib32z1packages:

然后接下来安装lib32stdc++6lib32z1打包:

$ sudo apt-get install lib32stdc++6 lib32z1

I discover my problem with enabling debugand infooption for gradlwcommand, that I run it on the root of project:

我发现我在启用debug和命令info选项方面的问题gradlw,我在项目的根目录上运行它:

First with this command:

首先使用此命令:

./gradlew --info --debug 

And next with this command:

接下来是这个命令:

./gradlew --info --debug :app:generateDebugSources

Output debug (On Android Gui this section run again and agian on the background without you know about error message ):

输出调试(在 Android Gui 上,此部分再次运行并在后台再次运行,而您不知道错误消息):

23:25:45.419 [ERROR] [system.err] Exception in thread "png-cruncher_10" java.lang.RuntimeException: Timed out while waiting for slave aapt process, make sure the aapt execute at /local/path/to/Android/sdk/build-tools/22.0.1/aapt can run successfully (some anti-virus may block it) or try setting environment variable SLAVE_AAPT_TIMEOUT to a value bigger than 5 seconds
23:25:45.419 [ERROR] [system.err]   at com.android.builder.png.AaptProcess.waitForReady(AaptProcess.java:108)
23:25:45.419 [ERROR] [system.err]   at com.android.builder.png.QueuedCruncher.creation(QueuedCruncher.java:110)
23:25:45.419 [ERROR] [system.err]   at com.android.builder.tasks.WorkQueue.run(WorkQueue.java:203)
23:25:45.419 [ERROR] [system.err]   at java.lang.Thread.run(Thread.java:745)

回答by Amir Saniyan

Check http://bintray.com(jcenter) or http://maven.org(mavenCentral) from your browser and change repositoriessetting in the build.gradleaccording to available site.

从浏览器检查http://bintray.com( jcenter) 或http://maven.org( mavenCentral) 并根据可用站点更改repositories设置build.gradle

回答by asifgoldpk

If you are using a proxy server then you might have to set the JVM parameters for your proxy.

如果您使用代理服务器,那么您可能必须为您的代理设置 JVM 参数。

Settings -> Gradle -> Gradle VM options: -Dhttp.proxyHost=1.2.3.4 -Dhttp.proxyPort=8080 Settings -> Compiler -> VM options: -Dhttp.proxyHost=1.2.3.4 -Dhttp.proxyPort=8080

设置 -> Gradle -> Gradle VM 选项:-Dhttp.proxyHost=1.2.3.4 -Dhttp.proxyPort=8080 设置 -> 编译器 -> VM 选项:-Dhttp.proxyHost=1.2.3.4 -Dhttp.proxyPort=8080

I had to restart the IDE for these settings to take effect.

我必须重新启动 IDE 才能使这些设置生效。

回答by Kay Liang

I've got similar problem today, and in my case I found it is because one of my external dependencies have difficulty being pulling from the internet.

我今天遇到了类似的问题,就我而言,我发现这是因为我的一个外部依赖项难以从 Internet 中提取。

Here's how I solved it:

这是我解决它的方法:

Step 1

第1步

Check the dependenciesin build.gradlefiles in the app (or the library modules, according to where your problem occured).

检查应用程序dependencies中的build.gradle文件(或库模块,根据问题发生的位置)。

For example, it might look like this:

例如,它可能如下所示:

dependencies {
    ...
    compile 'com.android.support:appcompat-v7:23.4.0'
    compile 'com.amazonaws:aws-android-sdk-iot:2.2.20'
}

Step 2

第2步

Guess which ones might be the root cause (ie. the one which looks harder to pull).

猜猜哪些可能是根本原因(即看起来更难拉的那个)。

In my case, I think 'com.amazonaws:aws-android-sdk-iot:2.2.20'looks suspicious, so I comment it out and then try to build Gradle again. This time, the Gradle build is successful.

就我而言,我认为'com.amazonaws:aws-android-sdk-iot:2.2.20'看起来很可疑,所以我将其注释掉,然后再次尝试构建 Gradle。这一次,Gradle 构建成功。

Step 3

第 3 步

Search for other artifact versions.

搜索其他工件版本。

In my case, I searched https://bintray.com/bintray/jcenter/com.amazonaws%3Aaws-android-sdk-iotand found 2.2.21, 2.2.22are also available (currently).

就我而言,我搜索了 https://bintray.com/bintray/jcenter/com.amazonaws%3Aaws-android-sdk-iot并发现2.2.212.2.22也可用(目前)。

I tried 2.2.21in my build.gradle, and the Gradle build works now!!

我想2.2.21在我build.gradle和摇篮建筑工作现在!

dependencies {
    ...
    compile 'com.amazonaws:aws-android-sdk-iot:2.2.21'
}

Other References

其他参考

To know more about external dependencies in Gradle, check these sites:

要了解有关 Gradle 中外部依赖项的更多信息,请查看以下站点:

回答by Ryan

Just providing my experience in case others run into the following scenario.

只是提供我的经验,以防其他人遇到以下情况。

The problem for me was one of my repositories was hosted on my companies network and not the public network. After VPN'ing I was able to "resolve the dependency."

我的问题是我的存储库之一托管在我的公司网络上,而不是公共网络上。在 VPN'ing 之后,我能够“解决依赖关系”。

回答by R M

I fixed mine by copying the Gradle settings in a working project and pasting them into the bad build.gradle file.

我通过复制工作项目中的 Gradle 设置并将它们粘贴到错误的 build.gradle 文件中来修复我的问题。