Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Studio doesn't recognize Facebook imports

I'm a begginer and I am trying to create an app with Facebook Integration.

I have done all the steps(Importing Facebook SDK in Module Structure,adding missing depedencies in gradle files,adding the dependencies module for my app project in Structure again). Everything seemed to be fine,I added A simple LoginButton in main_activity.xml) and no error showed up.

Since I tried to do all the facebook imports needed in MainActivity.java, they all turned red. Those were imports like:

    import com.facebook.Session;
    import com.facebook.SessionState;
    import com.facebook.UiLifecycleHelper;
    import com.facebook.widget.LoginButton;
    import com.facebook.widget.LoginButton.UserInfoChangedCallback;

and messages like "symbol session cannot be resolved". I googled it as much as I could,couldn't find a solution that worked for me. At the opposite, this didn't seem to have a problem:

    import com.facebook.login.widget.LoginButton;

Here is my Android Manifest File XML:

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.user.moviere" >

    <uses-permission android:name="android.permission.INTERNET"/>
    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/facebook_app_id"/>
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <activity android:name="com.facebook.LoginActivity"
            android:theme="@android:style/Theme.Translucent.NoTitleBar"
            android:label="@string/app_name" />
        <meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/facebook_app_id"/>

        <activity android:name="com.facebook.FacebookActivity"
            android:configChanges=
                "keyboard|keyboardHidden|screenLayout|screenSize|orientation"
            android:theme="@android:style/Theme.Translucent.NoTitleBar"
            android:label="@string/app_name" />
    </application>

</manifest>

And here is my build.gradle

    apply plugin: 'com.android.application'

android {
    compileSdkVersion 21
    buildToolsVersion '21.1.2'

    defaultConfig {
        applicationId "com.user.moviere"
        minSdkVersion 9
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}
repositories {
    mavenCentral()
}
dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    // compile project(':facebook')
    compile 'com.android.support:appcompat-v7:22.0.0'
    compile 'com.facebook.android:facebook-android-sdk:4.0.0'
    compile 'com.android.support:support-v4:22.0.0'
   }
like image 473
linous Avatar asked Mar 28 '15 11:03

linous


People also ask

Where should I import Android studio settings?

Drag and drop Android Studio into the Applications folder, then launch Android Studio. Select whether you want to import previous Android Studio settings, then click OK.


3 Answers

Ok, I created the project from the beginning,imported the FB SDK again. But the real problem with the imports was that Facebook SDK 4 has changed some of the functions,one of them is UiLifecycleHelper for example, it doesn't exist anymore.

Full details about all the changes is here:

https://developers.facebook.com/docs/android/upgrading-4.x

like image 64
linous Avatar answered Oct 17 '22 17:10

linous


yeah in the current update of the facebook sdk they have removed Session , now AccessToken, LoginManager and CallbackManager classes supercede and replace functionality in the Session class.

For more details go to - https://developers.facebook.com/docs/android/upgrading-4.x

like image 26
Kushagar Lall Avatar answered Oct 17 '22 19:10

Kushagar Lall


Update Facebook Dependency

compile 'com.facebook.android:facebook-android-sdk:4.8.0'

Need Permission in Manifest File

<uses-permission android:name="android.permission.INTERNET"/>

    <meta-data
        android:name="com.facebook.sdk.ApplicationName"
        android:value="@string/app_name" />
    <meta-data
        android:name="com.facebook.sdk.ApplicationId"
        android:value="@string/facebook_app_id" />

    <provider
        android:name="com.facebook.FacebookContentProvider"
        android:authorities="com.facebook.app.FacebookContentProvider1854328631556764"
        android:exported="true" />

Its Working

More Details :-

https://developers.facebook.com/docs/android/upgrading-4.x

like image 32
Keshav Gera Avatar answered Oct 17 '22 18:10

Keshav Gera