Search code examples
javaandroidandroid-studiofacebook-sdk-4.0

Facebook SDK could not be resolved in Android Studio


I followed this link here about how to use Facebook SDK in an Android App:

https://developers.facebook.com/docs/android/getting-started

I included compile 'com.facebook.android:facebook-android-sdk:4.+', in my app>gradle>dependecies, and then I tried to use these lines of code:

import com.facebook.FacebookSdk;

public class MyApplication extends Application {
    // Updated your class body:
    @Override
    public void onCreate() {
        super.onCreate();
        // Initialize the SDK before executing any other operations,
        FacebookSdk.sdkInitialize(getApplicationContext());
        AppEventsLogger.activateApp(this);
    }
}

as It is suggested in the page that I mentioned above. But, the problem is that my FacebookSdk and AppEventsLogger cannot be resolved. I don't understand why even that the synchronization is OK. This is my app>gradle file:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.3"

    defaultConfig {
        applicationId "com.my.pkg"
        minSdkVersion 15
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled true
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    ......
    compile 'com.facebook.android:facebook-android-sdk:4.+'
}

Solution

  • Add these lines in your build.gradle

    repositories {
        jcenter {
            url "http://jcenter.bintray.com/"
        }    
    }
    

    As well as it's not recommended to use + in compilation, so I suggest being specific by using like compile 'com.facebook.android:facebook-android-sdk:4.0.0'