【问题标题】:android- Gradle: An issue occurred configuring root project android studioandroid-Gradle:配置根项目android studio时出现问题
【发布时间】:2019-08-27 18:28:10
【问题描述】:

我从 eclipse 迁移到 android studio。我创建了一个新项目,我想在 genymotion 上运行它。当我按下运行图标时,它开始编译并给我这个错误:

Error:Gradle: A problem occurred configuring root project 'Khabar'.
> Could not resolve all dependencies for configuration ':classpath'.
   > Could not resolve com.android.tools.build:gradle:1.1.0.
     Required by:
         :Khabardar:unspecified
      > Could not GET 'https://jcenter.bintray.com/com/android/tools/build/gradle/1.1.0/gradle-1.1.0.pom'.
         > d29vzk4ow07wi7.cloudfront.net

这是我的 build.gradle 的一些部分:

    apply plugin: 'com.android.application'

android {
    compileSdkVersion 20
    buildToolsVersion "20.0.0"

    defaultConfig {
        applicationId "example.ir.khabar"
        minSdkVersion 8
        targetSdkVersion 20
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

根目录下的build.gradle:

    apply plugin: 'com.android.application'

android {
    compileSdkVersion 20
    buildToolsVersion "20.0.0"

    defaultConfig {
        applicationId "example.ir.khabar"
        minSdkVersion 8
        targetSdkVersion 20
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:20.0.0'
    compile files('libs/universal-image-loader-1.8.4-with-sources.jar')
}

你能帮帮我吗?我的 gradle 版本是 gradle-2.2.1-all

【问题讨论】:

  • 将 build.gradle 发布到根文件夹中。
  • @GabrieleMariotti 感谢您的回复,我编辑我的答案并在根文件夹中添加 build.gradle
  • 你有什么“buildscript”部分?
  • @mohamadbagheri 你确定你的文件在根目录吗?
  • 有更新的人吗?

标签: android


【解决方案1】:

对我来说,解决方案是为 jcenter 添加 http url,而不是 https:

buildscript {
    repositories {
        jcenter {
            url "http://jcenter.bintray.com/"
        }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.1.0'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

【讨论】:

  • 我应该在哪里添加?我项目中的 build.gradle 文件?
  • 我的在 Project build.gradle 文件中。
【解决方案2】:

除了Al's的回答,我还得把url放在allprojects里面:

allprojects {
    repositories {
        jcenter {
            url "http://jcenter.bintray.com/"
        }
    }
}

【讨论】:

    【解决方案3】:

    我在 Ubuntu Mate 18.04 上遇到了同样的问题。我可以通过用 openjdk 替换 ibm-java80-jdkibm-java80-jre 来修复它。另外,我确实将我的 DNS 更新为 cloudflare DNS。但我认为这与修复没有任何关系。

    【讨论】:

      【解决方案4】:

      在存储库部分的 gradle 中添加 google() 将解决您的问题..

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

      【讨论】:

        猜你喜欢
        • 2020-06-27
        • 2020-06-28
        • 2021-04-09
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-10-17
        • 2020-08-24
        相关资源
        最近更新 更多