无法解析com.android.tools.build:gradle:2.2.3 [英] Could not resolve com.android.tools.build:gradle:2.2.3

查看:159
本文介绍了无法解析com.android.tools.build:gradle:2.2.3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为一个移动应用程序项目工作,但经常在尝试运行该应用程序时出现以下错误:

I'm working on a mobile app project for work, but often when I attempt to run the application it gives me the following error:

错误:配置根项目'projectName'时出现问题. 无法解析配置':classpath'的所有依赖关系. 无法解析com.android.tools.build:gradle:2.2.3. 要求者: :projectName:未指定 离线模式下没有com.android.tools.build:gradle:2.2.3的缓存版本.

Error:A problem occurred configuring root project 'projectName'. Could not resolve all dependencies for configuration ':classpath'. Could not resolve com.android.tools.build:gradle:2.2.3. Required by: :projectName:unspecified No cached version of com.android.tools.build:gradle:2.2.3 available for offline mode.

我尝试了许多不同的操作,包括在设置中取消选中脱机工作"复选框,然后关闭并重新打开Android Studio,但似乎没有任何方法可以解决该问题.它可能会连续生成好几次,但是相同的错误不断弹出.然后,我必须尝试构建和制作应用程序,或者退出并重新打开Android Studios的变体.虽然没有任何一贯的作品.对于可能导致此问题的任何见解以及如何解决此问题,我们将不胜感激.

I have tried a number of different things including deselecting the Offline work checkbox in the settings and then closing and re-opening Android Studio, but nothing seems to fix the issue. It may build fine for a few times in a row, but that same error keeps popping up. Then I have to try variations of building and making the app, or exiting and re-opening Android Studios. Nothing consistently works though. Any insight into what may be causing this issue and how it can be fixed would be appreciated.

***更新:应要求,我已在我的应用程序gradle内容下方添加了

***Update: Upon request I have added below my app gradle content

apply plugin: 'com.android.application'

android {
compileSdkVersion 24
buildToolsVersion "24.0.1"
useLibrary 'org.apache.http.legacy'

dexOptions {
    javaMaxHeapSize "8g"
}

defaultConfig {
    applicationId "com.example"
    minSdkVersion 15
    targetSdkVersion 24
    versionCode 1
    versionName "1.0"

    multiDexEnabled true
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
    debug{ 
        debuggable true
    }
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:24.2.1'
compile 'com.android.support:design:24.2.1'
compile 'com.google.android.gms:play-services:9.4.0'
compile 'com.android.support:recyclerview-v7:24.2.1'
compile 'com.android.support:support-v4:24.2.1'

compile files('libs/gson-2.2.2.jar')
compile group: 'cz.msebera.android' , name: 'httpclient', version: '4.4.1.1'
compile 'com.facebook.stetho:stetho:1.3.1'
compile 'com.loopj.android:android-async-http:1.4.9'
}

推荐答案

事实证明,解决我特定问题的方法相对简单.错误消息有点欺骗,因为这不是脱机模式切换的问题,而是与gradle文件的混淆.这是我为解决此问题而采取的一些步骤:

It turns out the solution to my particular issue was relatively simple. The error message was a bit deceiving as this was not a problem with the offline mode switch, but rather confusion with the gradle file. Here are a few steps I took to fix the issue:

  1. 对于Android Studio 2.3,请转到文件">设置">渐变",然后选择使用默认的gradle包装器"选项.另外,请确保未选中离线工作"旁边的复选框,以防万一.
  2. 点击应用"按钮
  3. 在Android Studio"Gradle Scripts"部分下的build.gradle文件(以项目命名的文件)中,请确保您当前的构建gradle类路径与当前版本的Android Studio相匹配. Android Studio 2.3的示例:

  1. For Android Studio 2.3 go to File>Settings>Gradle and select the "Use default gradle wrapper" option. Also make sure the checkbox next to "Offline work" is unchecked just in case.
  2. Click the "Apply" button
  3. Within the build.gradle file (the one named after your project) under the "Gradle Scripts" section of Android Studio make certain that your current build gradle class path matches the current version of Android Studio. An example for Android Studio 2.3:

buildscript {
    repositories {
    jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.3.0'
    }
}

  • 还请在"Gradle脚本"部分中,确保gradle-wrapper.properties文件在分发URL中引用了正确的gradle文件.例如gradle 3.3:

  • Also within the Gradle Scripts section make sure that your gradle-wrapper.properties file is referencing the correct gradle file in the distribution URL. For example for gradle 3.3:

    distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip
    

  • 导航到C:\ Program Files \ Android \ Android Studio \ gradle,并确保有一个gradle文件夹,其名称与您使用的gradle相同.就我而言,我确保存在一个名为gradle-3.3的文件夹,其中包含一个名为gradle-3.3-all.zip的zip文件.在网上找到该zip文件相对容易.

  • Navigate to C:\Program Files\Android\Android Studio\gradle and ensure there is a gradle folder with the same name as the gradle you are using. In my case I ensured there is a folder named gradle-3.3 with a zip file named gradle-3.3-all.zip. It is relatively easy to find this zip file online.

    对我来说,当我这样做时,它还抱怨在.gradle文件夹中找不到gradle-3.3-all.zip文件.我可以通过将gradle-3.3-all.zip文件添加到C:\ Users \ yourUser.gradle \ wrapper \ dists \ gradle-3.3-all \ 55gk2rcmfc6p2dg9u9ohc3hw9中来解决此问题.我不确定该文件夹的所有人名称是否相同,但是无论使用哪个名称,这都是我去过的位置.如果所有这些方法均不起作用,我将尝试更改这些步骤,并希望它对您有用.

    For me when I did this it also complained about not finding the gradle-3.3-all.zip file in the .gradle folder. I was able to fix this by adding the gradle-3.3-all.zip file to C:\Users\yourUser.gradle\wrapper\dists\gradle-3.3-all\55gk2rcmfc6p2dg9u9ohc3hw9. I'm not sure if the folder has the same name for everyone, but whatever the name, that is the location I went to. If all this doesn't work I would try a variation of these steps, and hopefully it works for you.

    这篇关于无法解析com.android.tools.build:gradle:2.2.3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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