Android studio gradle not recognise com.google.code.gson:gson:2.3.1

匿名 (未验证) 提交于 2019-12-03 01:23:02

问题:

Developing app with Android studio using gradle. I have added this dependencies to it:

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' 

but it says :

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 

Full source for my build.gradle files

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

App:

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'  } 

回答1:

Define this in you gradle build script.

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


回答2:

Call mavenCentral() in your build.gradle .

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



易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!