解析失败:com.google.code.gson:gson:2.3.1

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

错误:(25, 13) 解析失败:com.google.code.gson:gson:2.3.1

在项目结构对话框中显示

build.gradle:应用程序


apply plugin:'com.android.application'

  android {

   compileSdkVersion 23
    buildToolsVersion "23.0.0 rc2"

  defaultConfig {
    applicationId "com.app.main"
    minSdkVersion 14
    targetSdkVersion 23
    versionCode 1
    versionName "1.0"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), proguard-rules.pro'
    }
}}

repositories {
    mavenCentral()
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.google.code.gson:gson:2.3.1'
compile 'com.android.support:support-v4:23.0.1'
compile 'com.google.android.gms:play-services:7.8.0'
compile 'com.facebook.android:facebook-android-sdk:4.5.0'
compile 'com.google.android.gms:play-services-base:7.8.0'
compile 'com.google.android.gms:play-services-gcm:7.8.0'
compile 'com.google.android.gms:play-services-maps:7.8.0'
compile 'com.google.android.gms:play-services-location:7.8.0'
compile project(':Uni_Image_Lod_Lib')   }

builde.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()
      }
  }

步骤如下:

Android Studio 版本 1.3.2

重启电脑

无效caches/Restart

黎明依赖

但没有什么可以改变的。现在解决这个问题的方法是什么。

一些变化后

apply plugin:'com.android.application'

  android {

   compileSdkVersion 23
    buildToolsVersion "23.0.1"

  defaultConfig {
    applicationId "com.app.main"
    minSdkVersion 14
    targetSdkVersion 23
    versionCode 1
    versionName "1.0"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), proguard-rules.pro'
    }
}}

repositories {
    mavenCentral()
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.google.code.gson:gson:2.3.1'
compile 'com.android.support:support-v4:23.0.1'
compile 'com.google.android.gms:play-services:7.8.0'
compile 'com.facebook.android:facebook-android-sdk:4.5.0'
compile project(':Uni_Image_Lod_Lib')   }

并得到错误重建

在离线模式下构建项目时检测到未解决的依赖项。请禁用离线模式,然后重试。

错误:配置项目“:app”时出现问题。

Could not resolve all dependencies for configuration ':app:_debugCompile'. Could not resolve com.google.code.gson:gson:2.3.1. Required by: APP:app:unspecified No cached version of com.google.code.gson:gson:2.3.1 available for offline mode. No cached version of com.google.code.gson:gson:2.3.1 available for offline mode.

然后我在 prefrences-> Build, Execution, deployment -> gradle.

中看到

项目级别设置为:

勾选使用本地 gradle 分发

全局gradle设置:

离线工作未勾选

compile 'com.google.code.gson:gson:2.3.1'

删除 .1 并编译

'com.google.code.gson:gson:2.3' 

as 2.3.1 还不稳定,还没有上线,这就是它给你的错误。也不要在编译时使用 +,因为据我所知,这不是最佳实践。

您可以简单地执行以下操作:

buildscript {
    repositories {
        mavenCentral()  //Add following 
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.2.3'
    }
}

allprojects {
    repositories {
         mavenCentral() // Add following
         jcenter()
    }
}