Ozeta
Ozeta

Reputation: 329

Can't import Facebook Sdk 3.23 in Android Studio 1.1

I'm new into Android Studio and Facebook SDK. I followed the guide reported here: https://developers.facebook.com/docs/android/getting-started till step 6.

but I'm unable to use none of Facebook's functions. I get compilation errors for every Facebook functions I try. Also, I get an "unable to resolve symbol" for import com.facebook.FacebookSdk. Is there something I'm doing wrong or I should configure before importing the library? I just created a new Empty Project

here the build.gradle of the Project:

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.1.0'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
        mavenCentral()
    }
}

and here the module for the app:

apply plugin: 'com.android.application'
android {
    compileSdkVersion 22
    buildToolsVersion "22.0.0"

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

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:22.0.0'
    compile 'com.facebook.android:facebook-android-sdk:3.23.0'
}

Upvotes: 1

Views: 1149

Answers (1)

brianfit
brianfit

Reputation: 1919

I pulled most of my hair out to figure this out, and it may not be universally applicable. But it solved this issue for me.

In your highest level build.gradle file, add the Maven Central repositories:

repositories {
    jcenter()       // Default repository
    mavenCentral()  //  You add this line
}

In the app-level build.gradle file, add this block:

dependencies {

    compile 'com.facebook.android:facebook-android-sdk:4.5.0' 
}

The SDK version has to be valid. You can check for the latest in the Maven Repo by looking here.

Now, here's the part were the Facebook Tutorial is opaque. "You can now import com.facebook.FacebookSDK" meant nothing to me, as a newbie to Android Studio (My app is in Cordova, and I usually only use Android Studio to compile) I kept trying to import that address as a module from the File > New menu. Nope. Path does not exist. Of course it doesn't. It's not a path. WTF. But then I noticed other "import" objects as lines of code in the main activity file. Light bulb. So THAT's what the Facebook Tutorial meant. It felt like unlocking Tutankhamun's puzzle.

I inserted the following line into my application's main activity file:

import com.facebook.appevents.*;

And THAT, my fellow frustrates, worked for me.

Upvotes: 3

Related Questions