Search code examples
androidandroid-studioandroid-gradle-pluginfacebook-android-sdkandroid-build

Getting error while adding Facebook SDK in build.gradle


I am working on a project where I need to implement facebook login. For that purpose I followed the steps from the developer website as mentioned. But unfortunately getting build error after adding'com.facebook.android:facebook-android-sdk:4.1.0' in build.gradleas follows

apply plugin: 'com.android.application'

android {
    compileSdkVersion 22
    buildToolsVersion "22.0.1"

    defaultConfig {
        applicationId "com.example.facebook"
        minSdkVersion 11
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}
repositories {
    mavenCentral()
}
dependencies {
    compile 'com.android.support:appcompat-v7:22.2.0'
    compile 'com.facebook.android:facebook-android-sdk:4.1.0'
}

Error log which I am getting:

Error:A problem occurred configuring project ':app'.

> Could not resolve all dependencies for configuration ':app:_debugCompile'.
> Could not resolve com.facebook.android:facebook-android-sdk:4.1.0.

     Required by: ExampleApp:app:unspecified

> No cached version of com.facebook.android:facebook-android-sdk:4.1.0 available for offline mode.
> No cached version of com.facebook.android:facebook-android-sdk:4.1.0 available for offline mode.

Please help me to resolve this issue which I am facing right for a couple of days. I am really helpless and stuck up with the solutions. Any kind of suggestions would be much useful to fix my issue.


Solution

  • Your log gives the answer:

    No cached version of com.facebook.android:facebook-android-sdk:4.1.0 available for offline mode.

    Gradle is in offline mode, so it cannot download a new version of your library. Go to Preferences > Build, Execution, Deployment > Build Tools > Gradle and disable "Offline work".

    Preferences can be accessed from here:
    enter image description here