1

I have only one Build.gradle file. My problem is that, when I'm trying to add new library for example gson inside dependency it fails

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

This is my Build.gradle file

apply plugin: 'com.android.application' buildscript { repositories { jcenter() mavenCentral() } dependencies { classpath 'com.android.tools.build:gradle:2.2.3' } } android { compileSdkVersion 19 buildToolsVersion "25.0.2" defaultConfig { applicationId "com.example" minSdkVersion 14 targetSdkVersion 19 versionCode 1 versionName "1" } sourceSets { main { manifest.srcFile 'AndroidManifest.xml' res.srcDirs = ['res'] assets.srcDirs = ['assets'] jniLibs.srcDir 'libs' } instrumentTest.setRoot('tests') debug.setRoot('build-types/debug') release.setRoot('build-types/release') } buildTypes { } } dependencies { compile fileTree(include: '*.jar', dir: 'libs') compile 'com.google.code.gson:gson:2.7' // compile 'com.squareup.retrofit2:retrofit:2.1.0' } task clean(type: Delete) { delete rootProject.buildDir } 
1
  • latest GSON library on Maven is 2.8.0 so try compile group: 'com.google.code.gson', name: 'gson', version: '2.8.0' Commented Feb 16, 2017 at 10:59

2 Answers 2

1

You didn't declare any repository (for the actual project). You just declared repositories for build-script dependencies. Those are dependencies the build-script itself needs to run like custom tasks, plugins etc.

Add a repositories block outside the buildscript block and define where to search for project dependencies in there.

Sign up to request clarification or add additional context in comments.

Comments

0

You can try with adding the jar files into the lib and adding it to the Gradle.

dependencies { compile files('libs/gson-x.x.x.jar') } 

you can download the jar from this link

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.