【问题标题】:Android studio gradle not recognise com.google.code.gson:gson:2.3.1Android studio gradle 无法识别 com.google.code.gson:gson:2.3.1
【发布时间】:2015-12-28 07:14:02
【问题描述】:

使用 gradle 在 Android Studio 中开发应用。我已经添加了这个依赖:

compile 'com.android.support:appcompat-v7:23.0.1'
compile 'com.squareup.retrofit:retrofit:1.9.0'
compile 'com.google.code.gson:gson:2.3.1'

但它说:

Error:A problem occurred configuring project ':app'.
> Could not download gson.jar (com.google.code.gson:gson:2.3.1)
   > Could not get resource 'https://jcenter.bintray.com/com/google/code/gson/gson/2.3.1/gson-2.3.1.jar'.
      > Could not GET 'https://jcenter.bintray.com/com/google/code/gson/gson/2.3.1/gson-2.3.1.jar'.
         > Connection to https://jcenter.bintray.com refused

我的 build.gradle 文件的完整源代码

项目:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()

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

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

allprojects {
    repositories {
        jcenter()
    }
}

应用:

apply plugin: 'com.android.application'


android {
    compileSdkVersion 23
    buildToolsVersion "23.0.1"

    defaultConfig {
        applicationId "domain.myapplication"
        minSdkVersion 11
        targetSdkVersion 23
        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:23.0.1'
    compile 'com.squareup.retrofit:retrofit:1.9.0'
    compile 'com.google.code.gson:gson:2.3.1'

}

【问题讨论】:

  • 将“mavenCentral()”添加到您的存储库中,例如 jcenter()。
  • @ThomasR。删除 jcenter 一个或附加它?我以前测试过。为此,我再次问它
  • 但只是暂时的,当您遇到 jcenter 连接问题时。除非您别无选择,否则应始终使用 jcenter 而非 mavenCentral()
  • 存储库 { mavenCentral() maven { } }
  • 这里的问题 99% 肯定是连接问题。如果它曾经工作,这应该是暂时的问题

标签: android android-studio gradle


【解决方案1】:

在你的 gradle 构建脚本中定义它。

buildscript {
  repositories {
    mavenCentral()
    jcenter()
  }
  dependencies {
    ...
  }
}

allprojects {
  repositories {
    mavenCentral()
  }
}

【讨论】:

  • 错误:(26, 13) 无法解决: com.google.code.gson:gson:2.3 错误:(25, 13) 无法解决: com.squareup.retrofit:retrofit:1.9 .0
  • 编译'com.squareup.retrofit:retrofit:2.0.0-beta2'
  • 即使在“使用 gradle 文件同步项目”之后?
  • 尝试不使用 jcenter。将此注释掉,然后重试。你有防火墙或类似的东西吗?
  • 如果我删除 jcenter 然后它给出另一个错误:错误:(25、13)无法解决:com.squareup.retrofit:retrofit:1.9.0
【解决方案2】:

在您的 build.gradle 中调用 mavenCentral()

repositories {
    mavenCentral()
}
dependencies {

 compile fileTree(dir: 'libs', include: ['*.jar'])
 compile 'com.google.code.gson:gson:2.3' 

}

add maven repository to build.gradle

Failed to resolve: com.google.code.gson:gson:2.3.1

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多