简体   繁体   English

无法解决com.android.tools.build:gradle:2.2.3

[英]Could not resolve 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: 我正在开发一个移动应用程序项目,但是当我尝试运行应用程序时,它会给我以下错误:

Error:A problem occurred configuring root project 'projectName'. 错误:配置根项目'projectName'时出现问题。 Could not resolve all dependencies for configuration ':classpath'. 无法解析配置':classpath'的所有依赖项。 Could not resolve com.android.tools.build:gradle:2.2.3. 无法解决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. 需要:: projectName:unspecified没有缓存版本的com.android.tools.build:gradle:2.2.3可用于离线模式。

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. 我尝试了很多不同的事情,包括在设置中取消选择离线工作复选框,然后关闭并重新打开Android Studio,但似乎没有什么可以解决这个问题。 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. 然后,我必须尝试构建和制作应用程序的变体,或退出和重新打开Android工作室。 Nothing consistently works though. 没有什么能持续有效。 Any insight into what may be causing this issue and how it can be fixed would be appreciated. 任何洞察可能导致此问题的原因以及如何解决该问题将不胜感激。

***Update: Upon request I have added below my app gradle content ***更新:根据要求,我已添加以下我的应用程序gradle内容

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

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. 错误消息有点欺骗,因为这不是离线模式切换的问题,而是与gradle文件混淆。 Here are a few steps I took to fix the issue: 以下是我为解决此问题而采取的一些步骤:

  1. For Android Studio 2.3 go to File>Settings>Gradle and select the "Use default gradle wrapper" option. 对于Android Studio 2.3,请转到文件>设置> Gradle,然后选择“使用默认gradle包装器”选项。 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. 在Android Studio的“Gradle Scripts”部分下的build.gradle文件(以项目命名的文件)中,确保您当前的构建gradle类路径与当前版本的Android Studio匹配。 An example for Android Studio 2.3: Android Studio 2.3的一个示例:

     buildscript { repositories { jcenter() } dependencies { classpath 'com.android.tools.build:gradle:2.3.0' } } 
  4. Also within the Gradle Scripts section make sure that your gradle-wrapper.properties file is referencing the correct gradle file in the distribution URL. 同样在Gradle Scripts部分中,确保您的gradle-wrapper.properties文件引用了分发URL中的正确gradle文件。 For example for gradle 3.3: 例如对于gradle 3.3:

     distributionUrl=https\\://services.gradle.org/distributions/gradle-3.3-all.zip 
  5. 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. 导航到C:\\ Program Files \\ Android \\ Android Studio \\ gradle并确保有一个与您正在使用的gradle同名的gradle文件夹。 In my case I ensured there is a folder named gradle-3.3 with a zip file named gradle-3.3-all.zip. 在我的情况下,我确保有一个名为gradle-3.3的文件夹,其中包含一个名为gradle-3.3-all.zip的zip文件。 It is relatively easy to find this zip file online. 在线查找此zip文件相对容易。

  6. Delete the .gradle folder in C:\\Users\\yourUser with yourUser being whichever user your Android Studio project is under. 删除C:\\ Users \\ yourUser中的.gradle文件夹,其中您的Android Studio项目所属的用户就是您的用户。
  7. Close Android Studio and restart. 关闭Android Studio并重新启动。 It should begin the gradle sync process and rebuild the .gradle file. 它应该开始gradle同步过程并重建.gradle文件。

For me when I did this it also complained about not finding the gradle-3.3-all.zip file in the .gradle folder. 对我来说,当我这样做时,它还抱怨没有在.gradle文件夹中找到gradle-3.3-all.zip文件。 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. 我能够通过将gradle-3.3-all.zip文件添加到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. 如果所有这些都不起作用,我会尝试这些步骤的变体,并希望它适合你。

The reason why it is failing is because it could not compile one of the libraries you included. 失败的原因是因为它无法编译您包含的库之一。 Perhaps, try removing the one you suspect and try again. 也许,尝试删除您怀疑的那个,然后再试一次。 But most of the times, a rebuild of the project should resolve dependencies. 但大多数情况下,项目的重建应解决依赖关系。

I've had the same pb, managed to resolve it adding in gradle.properties 我有相同的pb,设法解决它添加gradle.properties

systemProp.https.proxyHost=<my proxy hostname>
systemProp.https.proxyPort=<my proxy port>

I was missing HTTPS property, there was only HTTP setted so it was working sometimes, and not for the https links gradle used. 我缺少HTTPS属性,只有HTTP设置,所以它有时工作,而不是使用的https链接gradle。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM