Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

{Facebook Login} java.lang.NoClassDefFoundError: android.support.v4.content.LocalBroadcastManager

I've pretty much followed this guide to the letter, however, when the application is launched and the Facebook session should be created the app crashes. I'm thinking the libraries aren't being included in the build...

package com.firstandroidapp;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.widget.TextView;
import com.facebook.*;
import com.facebook.model.*;

public class MainActivity extends Activity {

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

    // 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.executeMeRequestAsync(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() + "!");
              }
            }
          });
        }
      }
    });
  }

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

}

Here's the exception stack:

10-16 14:13:30.627: E/AndroidRuntime(28793): FATAL EXCEPTION: main
10-16 14:13:30.627: E/AndroidRuntime(28793): java.lang.NoClassDefFoundError: android.support.v4.content.LocalBroadcastManager
10-16 14:13:30.627: E/AndroidRuntime(28793):    at com.facebook.Session.postActiveSessionAction(Session.java:1327)
10-16 14:13:30.627: E/AndroidRuntime(28793):    at com.facebook.Session.setActiveSession(Session.java:790)
10-16 14:13:30.627: E/AndroidRuntime(28793):    at com.facebook.Session.openActiveSession(Session.java:890)
10-16 14:13:30.627: E/AndroidRuntime(28793):    at com.facebook.Session.openActiveSession(Session.java:830)
10-16 14:13:30.627: E/AndroidRuntime(28793):    at com.mumin.facebookconnect.FBAuth.onCreate(FBAuth.java:21)
10-16 14:13:30.627: E/AndroidRuntime(28793):    at android.app.Activity.performCreate(Activity.java:5104)
10-16 14:13:30.627: E/AndroidRuntime(28793):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
10-16 14:13:30.627: E/AndroidRuntime(28793):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2260)
10-16 14:13:30.627: E/AndroidRuntime(28793):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2356)
10-16 14:13:30.627: E/AndroidRuntime(28793):    at android.app.ActivityThread.access$600(ActivityThread.java:150)
10-16 14:13:30.627: E/AndroidRuntime(28793):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1244)
10-16 14:13:30.627: E/AndroidRuntime(28793):    at android.os.Handler.dispatchMessage(Handler.java:99)
10-16 14:13:30.627: E/AndroidRuntime(28793):    at android.os.Looper.loop(Looper.java:137)
10-16 14:13:30.627: E/AndroidRuntime(28793):    at android.app.ActivityThread.main(ActivityThread.java:5195)
10-16 14:13:30.627: E/AndroidRuntime(28793):    at java.lang.reflect.Method.invokeNative(Native Method)
10-16 14:13:30.627: E/AndroidRuntime(28793):    at java.lang.reflect.Method.invoke(Method.java:511)
10-16 14:13:30.627: E/AndroidRuntime(28793):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:795)
10-16 14:13:30.627: E/AndroidRuntime(28793):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:562)
10-16 14:13:30.627: E/AndroidRuntime(28793):    at dalvik.system.NativeStart.main(Native Method)
10-16 14:13:38.175: I/Process(28793): Sending signal. PID: 28793 SIG: 9
like image 373
MK3GTX Avatar asked Dec 09 '22 12:12

MK3GTX


1 Answers

Just replace

     YourProject\lib\android-support-v4.jar 

with

     facebook-android-sdk-x.xx.x\libs\android-support-v4.jar 

where x.xx.x is the facebook sdk version, e.g. 3.21.0

like image 192
user2968230 Avatar answered Dec 11 '22 09:12

user2968230