Frage

I have been trying to figure this out for a couple of days but I give up.

Here are the errors I am getting:

Error:(9, 1) error: package com.facebook does not exist
Error:(10, 1) error: package com.facebook.model does not exist
Error:(11, 20) error: package com.facebook does not exist
Error:(21, 58) error: package Session does not exist
Error:(21, 9) error: cannot find symbol variable Session
Error:(48, 9) error: cannot find symbol variable Session

I am using Android Studio 0.58 and Facebook SDK 3.14

I downloaded the facebook SDK, extracted it, then went to File > Import Module and selected the "Facebook" module. Did not help.

I took the jar file and put it in my libs folder. Clean. Sync. No help.

I added to my build.gradle (as suggested by many searches). Did a sync. I checked and the "android-support-v4.jar" is in my dependencies in the Project Structure. Still no help.

Here is my build.gradle:

apply plugin: 'android'

android {
compileSdkVersion 19
buildToolsVersion '19.0.3'

defaultConfig {
    minSdkVersion 9
    targetSdkVersion 19
    versionCode 6
    versionName "0.3.0"
}
signingConfigs{
    release {
        storeFile file("path")
        storePassword "password"
        keyAlias "alias"
        keyPassword "password"
    }
buildTypes {
    release {
        runProguard true
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        debuggable false
        signingConfig signingConfigs.release
        zipAlign true
        }
    }
}
}
dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:appcompat-v7:19.+'
    compile 'com.google.android.gms:play-services:+'
    compile files('libs/libGoogleAnalyticsServices.jar')
    compile files('libs/android-support-v4.jar')
}

Here is my Android Manifest.xml

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

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

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme"
     >
    <meta-data
        android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version"
         />
    <meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/app_id"/>


    <activity
        android:name="com.understandingyourbody.uyb.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.understandingyourbody.uyb.WordPress"
        android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.WORDPRESS" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>

    <activity
        android:name="com.understandingyourbody.uyb.Facebook"
        android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.FACEBOOK" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>

    <activity android:name="com.google.android.gms.ads.AdActivity"
        android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>

</application>

And here is my Java

package com.understandingyourbody.uyb;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.widget.TextView;

import com.facebook.*;
import com.facebook.model.*;
import com.facebook.Session;

public class Facebook extends Activity {

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.facebook);

    // start Facebook Login
    Session.openActiveSession(this, true, new Session.StatusCallback() {

        // callback when session changes state
        @Override
        public void call(Session session, SessionState state, Exception exception) {
            if (session.isOpened()) {

                // make request to the /me API
                Request.newMeRequest(session, new Request.GraphUserCallback() {

                    // callback after Graph API response with user object
                    @Override
                    public void onCompleted(GraphUser user, Response response) {
                        if (user != null) {
                            TextView welcome = (TextView) findViewById(R.id.welcome);
                            welcome.setText("Hello " + user.getName() + "!");
                        }
                    }
                }).executeAsync();
            }
        }
    });
}

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    Session.getActiveSession().onActivityResult(this, requestCode, resultCode, data);
}

}
War es hilfreich?

Lösung

I found the answer here: https://stackoverflow.com/a/23577782/3554758

I was adding an "Android Library" instead of choosing "Import Existing Prohect" It works great now enter image description here

Andere Tipps

When importing the module, don't forget to add it as a dependency:

dependencies {
    compile project(':facebooksdk') // The name of the module.
}
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top