Jemo Mgebrishvili
Jemo Mgebrishvili

Reputation: 5497

Failed to resolve libraries added inside Build.Gradle dependency

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
}

Upvotes: 1

Views: 366

Answers (2)

Alvin Varghese
Alvin Varghese

Reputation: 689

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

Upvotes: 0

Vampire
Vampire

Reputation: 38734

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.

Upvotes: 1

Related Questions