Chuck D
Chuck D

Reputation: 343

Facebook SDK import statement doesn't find classes

I've already read up on tons of variations of this problem, but I can't seem to get the import com.facebook. line to work in my application using Android Studio 2.0.

I have a main application and a library module, and I'm using the Facebook SDK in the library module. Here's my top project gradle:

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

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

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

task clean(type: Delete) {
    delete rootProject.buildDir
}

And the gradle for my library:

apply plugin: 'com.android.library'

android {
    compileSdkVersion 23
    buildToolsVersion "22.0.1"

    defaultConfig {
        minSdkVersion 19
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.3.0'
    compile 'com.google.android.gms:play-services:8.4.0'
    compile 'com.facebook.android:facebook-android-sdk:4.11.0'
}

Now, when I sync gradle, it does seem to build all of the intermediate stuff like it should. However when I try to do an import statement, the only options I get are:

import com.facebook.*
import com.facebook.R

No other options are available. If I try to do this:

import com.facebook.FacebookSdk

The word FacebookSdk is in red, because it can't find it.

I've been beating on this all morning long. I'm converting an old Eclipse project, but this started out as a brand new Android Studio project (not an import from an old Eclipse project). It seems as if there's another Facebook SDK floating around without any exports in it, but I'll be darned if I can't find it. I've also tried quite a few earlier versions of the Facebook SDK, and they all do the same thing.

Where in the heck am I going wrong here?

Upvotes: 1

Views: 797

Answers (1)

Chuck D
Chuck D

Reputation: 343

Answered my own question! Little did I know that you have to have a successful build BEFORE you can add the import statements. I had added compile 'com.facebook.android:facebook-android-sdk:4.11.0' then immediately tried to import com.facebook.FacebookSdk without doing a successful build first.

To be fair, step 6 of the Google quick start does say 'Build your project', but the importance of doing this before adding any SDK code kinda bounced off me.

Upvotes: 2

Related Questions