简体   繁体   English

AndroidStudio - Gradle Refresh失败

[英]AndroidStudio - Gradle Refresh Failed

I was using the up to date version of android studio to build my app for android. 我正在使用android studio的最新版本来构建我的Android应用程序。 The gradle wrapper set up the gradle installation and the project was build without errors. gradle包装器设置gradle安装,项目构建没有错误。

Eventually I started getting one error each time I restarted. 最后,每次重新启动时,我都会收到一个错误。

Gradle: A problem occurred configuring project ':App'. Gradle:配置项目':App'时出现问题。

Could not resolve all dependencies for configuration ':App:classpath'. 无法解析配置的所有依赖项':App:classpath'。 Could not resolve com.android.tools.build:gradle:0.5.+. 无法解决com.android.tools.build:gradle:0.5.+。 Required by: App:App:unspecified 要求:App:App:未指定

org.slf4j.spi.LocationAwareLogger.log(Lorg/slf4j/Marker;Ljava/lang/String;ILjava/lang/String;[Ljava/lang/Object;Ljava/lang/Throwable;)V org.slf4j.spi.LocationAwareLogger.log(Lorg / SLF4J /标记; Ljava /郎/字符串; ILjava /郎/字符串; [Ljava /郎/对象; Ljava /郎/ Throwable的;)V

The issue could be fixed by executing gradlew again and builds went fine. 可以通过再次执行gradlew来解决问题,并且构建正常。 But after the 0.3 android studio update and android plugin update to 0.6.+ I can't even execute gradlew anymore without getting this error message. 但是在0.3 android studio更新和android插件更新到0.6之后。+我甚至无法执行gradlew而不会收到此错误消息。

I tried uninstalling android studio with all its configuration files, deleted the .gradle folders in the project and home directory and even the .m2 repository. 我尝试用其所有配置文件卸载android studio,删除项目和主目录中的.gradle文件夹,甚至删除.m2存储库。 I can't even start a new android project, it fails with the same error, so there should be no issue with my build.grade 我甚至无法启动一个新的android项目,它失败了同样的错误,所以我的build.grade应该没有问题

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.6.+'
    }
}
apply plugin: 'android'

repositories {
    mavenCentral()
}

android {
    compileSdkVersion 18
    buildToolsVersion "18.1.1"

    defaultConfig {
        minSdkVersion 15
        targetSdkVersion 18
    }

    sourceSets {
        main {
            manifest.srcFile 'src/main/AndroidManifest.xml'
            java.srcDirs = ['src/main/java']
            res.srcDirs = ['src/main/res']
        }
    }
}

dependencies {
    compile 'com.android.support:support-v4:18.0.0'
    compile 'org.jsoup:jsoup:1.7.2'
}

I was able to solve the problem. 我能够解决问题。 I don't know what caused the bug, but its gone. 我不知道是什么导致了这个bug,但它消失了。 Steps to fix: 修复步骤:

  • Backup and delete existing project 备份和删除现有项目
  • Deinstalling android studio 0.3 卸载android studio 0.3
  • Deleting .gradle/ and .androidstudio/ in user directory 删除用户目录中的.gradle /和.androidstudio /
  • Installing android studio 0.2.X 安装android studio 0.2.X
  • Patching android studio to 0.2.9 修补android studio到0.2.9
  • Reimporting code backup 重新导入代码备份

This is known issue http://tools.android.com/knownissues 这是已知问题http://tools.android.com/knownissues

The Android Gradle plugin 0.6.2 was published with incorrect dependencies. 发布了Android Gradle插件0.6.2,其中包含不正确的依赖项。 There isn't a way to delete it, so we have instead release 0.6.3 which fixes the problems. 没有办法删除它,所以我们改为发布0.6.3修复问题。 Just switch your version from 0.6.+ to 0.6.3, or run gradlew with --refresh-dependencies to force Gradle to look for an update. 只需将版本从0.6。+切换到0.6.3,或使用--refresh-dependencies运行gradlew以强制Gradle查找更新。

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

instead of 代替

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

Make sure you have the latest version of Gradle as the latest Android Studio needed 1.8. 确保您拥有最新版本的Gradle,因为最新的Android Studio需要1.8。 Also make sure that you have downloaded updates through the Android SDK that is bundled in Studio. 另外,请确保您已通过Studio中捆绑的Android SDK下载了更新。 Tools-> Android-> SDK Manager

You will need the latest Android Support Library 您将需要最新的Android支持库

I was facing the same issue then I upgrade my react-native version :- 我面临同样的问题然后我升级我的react-native版本: -

react-native upgrade

its works fine for me now 它现在对我来说很好

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

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