未能解决:com.google.code.gson:gson:2.3.1

5

Error:(25, 13) 无法解析:com.google.code.gson:gson:2.3.1

请在“项目结构”对话框中查看

build.gradle:app


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:Project


  // 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

重启计算机

无效缓存/重新启动

更新依赖项

但是,没有任何变化。现在该怎么办呢?

进行一些更改后

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”时出现问题。

无法解决配置“:app:_debugCompile”的所有依赖项。 无法解决com.google.code.gson:gson:2.3.1。 所需的: APP:app:未指定 在离线模式下没有缓存版本的com.google.code.gson:gson:2.3.1可用。 在离线模式下没有缓存版本的com.google.code.gson:gson:2.3.1可用。

然后我在首选项中看到了构建、执行和部署 -> gradle。

项目级别设置为:

勾选使用本地gradle分发

全局gradle设置为:

未勾选离线工作


首先使用buildToolsVersion "23.0.1",然后删除compile 'com.google.android.gms:play-services-base:7.8.0',最后清理并gradle您的项目。 - IntelliJ Amiya
1
@IntelliJAmiya 感谢您的快速回复,我按照您的建议操作了,但错误仍然存在。 - RaRa
尝试将mavenCentral()更改为jcenter()。 - Rittel
1
@Rittel 谢谢,但问题还未解决。 - RaRa
看起来你正在离线工作。 - Gabriele Mariotti
@GabrieleMariotti 怎么上线? - RaRa
2个回答

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

移除.1并使其编译通过

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

as 2.3.1 还没有稳定发布,这就是为什么会出现错误的原因。此外,在编译时不要使用 +,据我所知,这不是最佳实践。


14

你可以简单地按照以下步骤进行:

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

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接