penta
penta

Reputation: 2596

Not able to add dependecy in gradle(Android Studio)

I am trying to add this dependency https://github.com/hoang8f/android-flat-button in to my android studio project and I am getting

 Error:(26, 13) Failed to resolve: info.hoang8f:fbutton:1.0.5

I am able to add google play services dependency easily without any problems.

Below is my build.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 22
    buildToolsVersion "22.0.1"

    defaultConfig {
        applicationId "com.example.planner"
        minSdkVersion 15
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}


dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:appcompat-v7:22.2.1'
    compile 'com.google.android.gms:play-services:7.5.0'
    compile 'info.hoang8f:fbutton:1.0.5'
}

Solutions tried:- 1.)Gradle is working in online mode not offline. 2.)Cleaned and builded/rebuilded the project.

3.) Changed to

repositories {
    mavenCentral()
}

in my root gradle file

4.) Tools->android->Sync Project with gradle files

Still no luck in making it work.

P.S.:- Not that it effects the questions, I faced the same problem while trying to add parse sdk via gradle, so I added the jar file independently.

Upvotes: 4

Views: 1030

Answers (5)

Silwester
Silwester

Reputation: 418

I cloned the project and used "demo" module to test the lib. The lib that you needed was downloaded successfully and this is expected, because it exists in the maven repo

The only point I noticed - probably you may have problems with gradle, because there's runProguard command, that is not used in gradle no more. So you may just delete it or change to minifyEnabled false.

After doing this, demo project assembles successfully

Upvotes: 0

piotrek1543
piotrek1543

Reputation: 19351

Did you noticed how looks like build.gradle of a demo project? https://github.com/hoang8f/android-flat-button/blob/master/demo/build.gradle

apply plugin: 'android'

android {
    compileSdkVersion 19
    buildToolsVersion '19.1.0'

    defaultConfig {
        minSdkVersion 9
        targetSdkVersion 19
        versionCode 2
        versionName "1.1"
    }
    buildTypes {
        release {
            runProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    } }

dependencies {
    compile 'com.android.support:appcompat-v7:19.+'
    compile 'com.larswerkman:HoloColorPicker:1.4'
    compile fileTree(dir: 'libs', include: ['*.jar']) //    compile project(':library')
    compile 'info.hoang8f:fbutton:1.0.5'
 }

Check if you're not missing something in your Gradle file or you put something wrong

EDIT: I've put whole your build.gradle file into my new project and it's work fine.

If rebuilding not help, create a new clean project and put this build.gradle. Tell me is it works with new project.

EDIT2:

In your project you have two build.gradle change the second one to

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.5.0'
        classpath 'com.google.gms:google-services:1.5.0-beta2'
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

Upvotes: 1

Prashant Solanki
Prashant Solanki

Reputation: 660

I had the same problem. Invalidate cache and restart your android studio. Then sync gradle.

Upvotes: 0

Photon Point
Photon Point

Reputation: 808

Please try this. Add fbutton-1.0.5.aar file into your lib folder.

repositories {
        flatDir {
            dirs 'libs'
        }
    }

Add aar file into dependencies.

dependencies {
    compile(name:'ARFile', ext:'aar')
}

Upvotes: 1

hugerde
hugerde

Reputation: 949

add

repositories { mavenCentral() }

include android tag

    android {
compileSdkVersion 22
buildToolsVersion "22.0.1"

defaultConfig {
    applicationId "com.example.planner"
    minSdkVersion 15
    targetSdkVersion 22
    versionCode 1
    versionName "1.0"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
repositories {
    mavenCentral()
   }}

Upvotes: 1

Related Questions