title: Can't get facebook login to work on android
body: <p>Can't get Facebook login to work - the app always crashes as soon as I open it. Have been using this (<a href="https://developers.facebook.com/docs/android/scrumptious/authenticate" rel="nofollow">https://developers.facebook.com/docs/android/scrumptious/authenticate</a>) tutorial and redone it about 5 times, but still nothing. </p>
  
  <h3> SplashFragment.java </h3>
  
  <pre><code>package com.example.braucamkopa;
  
  import android.os.Bundle;
  import android.support.v4.app.Fragment;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  
  public class SplashFragment extends Fragment {
  
  @Override
  public View onCreateView(LayoutInflater inflater, 
          ViewGroup container, Bundle savedInstanceState) {
      View view = inflater.inflate(R.layout.splash, 
              container, false);
      return view;
  }
  }
  </code></pre>
  
  <h3> SelectionFragment.java </h3>
  
  <pre><code>package com.example.braucamkopa;
  
  
  import android.os.Bundle;
  import android.support.v4.app.Fragment;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  
  public class SelectionFragment extends Fragment {
  
  private static final String TAG = "SelectionFragment";
  
  @Override
  public View onCreateView(LayoutInflater inflater, 
          ViewGroup container, Bundle savedInstanceState) {
      super.onCreateView(inflater, container, savedInstanceState);
      View view = inflater.inflate(R.layout.selection, 
              container, false);
      return view;
  }   
  }
  </code></pre>
  
  <h3> MainLogin.java</h3>
  
  <pre><code>package com.example.braucamkopa;
  
  import com.facebook.Session;
  import com.facebook.Session.StatusCallback;
  import com.facebook.SessionState;
  import com.facebook.UiLifecycleHelper;
  import android.content.Intent;
  import android.os.Bundle;
  import android.support.v4.app.Fragment;
   import android.support.v4.app.FragmentActivity;
  import android.support.v4.app.FragmentManager;
  import android.support.v4.app.FragmentTransaction;
  
  public class MainLogin extends FragmentActivity {
  
  private static final int SPLASH = 0;
  private static final int SELECTION = 1;
  private static final int FRAGMENT_COUNT = SELECTION +1;
  
  private Fragment[] fragments = new Fragment[FRAGMENT_COUNT];
  private UiLifecycleHelper uiHelper;
  private Session.StatusCallback callback = 
      new Session.StatusCallback() {
      @Override
      public void call(Session session, 
              SessionState state, Exception exception) {
          onSessionStateChange(session, state, exception);
      }
  };
  
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      uiHelper = new UiLifecycleHelper(this, callback);
      uiHelper.onCreate(savedInstanceState);
  
      setContentView(R.layout.mainlogin);
  
      FragmentManager fm = getSupportFragmentManager();
      fragments[SPLASH] = fm.findFragmentById(R.id.splashFragment);
      fragments[SELECTION] = fm.findFragmentById(R.id.selectionFragment);
  
      FragmentTransaction transaction = fm.beginTransaction();
      for(int i = 0; i &lt; fragments.length; i++) {
          transaction.hide(fragments[i]);
      }
      transaction.commit();
  }
  
  private void showFragment(int fragmentIndex, boolean addToBackStack) {
      FragmentManager fm = getSupportFragmentManager();
      FragmentTransaction transaction = fm.beginTransaction();
      for (int i = 0; i &lt; fragments.length; i++) {
          if (i == fragmentIndex) {
              transaction.show(fragments[i]);
          } else {
              transaction.hide(fragments[i]);
          }
      }
      if (addToBackStack) {
          transaction.addToBackStack(null);
      }
      transaction.commit();
  }
  
  private boolean isResumed = false;
  
  @Override
  public void onResume() {
      super.onResume();
      uiHelper.onResume();
      isResumed = true;
  }
  
  @Override
  public void onPause() {
      super.onPause();
      uiHelper.onPause();
      isResumed = false;
  }
  
  @Override
  public void onActivityResult(int requestCode, int resultCode, Intent data) {
      super.onActivityResult(requestCode, resultCode, data);
      uiHelper.onActivityResult(requestCode, resultCode, data);
  }
  
  @Override
  public void onDestroy() {
      super.onDestroy();
      uiHelper.onDestroy();
  }
  
  @Override
  protected void onSaveInstanceState(Bundle outState) {
      super.onSaveInstanceState(outState);
      uiHelper.onSaveInstanceState(outState);
  }
  
  private void onSessionStateChange(Session session, SessionState state, Exception        exception) {
      // Only make changes if the activity is visible
      if (isResumed) {
          FragmentManager manager = getSupportFragmentManager();
          // Get the number of entries in the back stack
          int backStackSize = manager.getBackStackEntryCount();
          // Clear the back stack
          for (int i = 0; i &lt; backStackSize; i++) {
              manager.popBackStack();
          }
          if (state.isOpened()) {
              // If the session state is open:
              // Show the authenticated fragment
              showFragment(SELECTION, false);
          } else if (state.isClosed()) {
              // If the session state is closed:
              // Show the login fragment
              showFragment(SPLASH, false);
          }
      }
  }
  
  protected void onResumeFragments() {
  
      Session session = Session.getActiveSession();
  
      if (session != null &amp;&amp; session.isOpened()) {
          // if the session is already open,
          // try to show the selection fragment
          showFragment(SELECTION, false);
      } else {
          // otherwise present the splash screen
          // and ask the person to login.
          showFragment(SPLASH, false);
      }
  }
  }
  </code></pre>
  
  <h3>Android Manifest</h3>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="com.example.braucamkopa"
  android:versionCode="1"
  android:versionName="1.0" &gt;
  
  &lt;uses-sdk
      android:minSdkVersion="12"
      android:targetSdkVersion="19" /&gt;
  
     &lt;uses-permission android:name="android.permission.INTERNET" /&gt;
     &lt;uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"&gt;&lt;/uses-permission&gt;
  
  &lt;application
      android:allowBackup="true"
      android:icon="@drawable/ic_launcher"
      android:label="@string/app_name"
      android:theme="@style/AppTheme" &gt;
      &lt;activity
          android:name="com.example.braucamkopa.MainLogin"
          android:label="@string/app_name"
          android:screenOrientation="portrait" &gt;
          &lt;intent-filter&gt;
              &lt;action android:name="android.intent.action.MAIN" /&gt;
  
              &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
          &lt;/intent-filter&gt;
      &lt;/activity&gt;
      &lt;activity
          android:name=".SplashFragment"
          android:label="@string/app_name" &gt;
      &lt;/activity&gt;            
      &lt;activity
          android:name=".SelectionFragment"
          android:label="@string/app_name" &gt;
      &lt;/activity&gt;
  &lt;meta-data
          android:name="com.facebook.sdk.ApplicationId"
          android:value="@string/app_id" /&gt;
  &lt;/application&gt;
  
  &lt;/manifest&gt;
  </code></pre>
  
  <h3>LogCat</h3>
  
  <pre><code>07-03 20:23:39.674: I/dalvikvm(25239): Could not find method android.support.v4.content.LocalBroadcastManager.getInstance, referenced from method com.facebook.UiLifecycleHelper.&lt;init&gt;
  07-03 20:23:39.674: W/dalvikvm(25239): VFY: unable to resolve static method 835: Landroid/support/v4/content/LocalBroadcastManager;.getInstance (Landroid/content/Context;)Landroid/support/v4/content/LocalBroadcastManager;
  07-03 20:23:39.674: D/dalvikvm(25239): VFY: replacing opcode 0x71 at 0x0019
  07-03 20:23:39.674: I/dalvikvm(25239): Could not find method android.support.v4.content.LocalBroadcastManager.unregisterReceiver, referenced from method com.facebook.UiLifecycleHelper.onPause
  07-03 20:23:39.674: W/dalvikvm(25239): VFY: unable to resolve virtual method 838: Landroid/support/v4/content/LocalBroadcastManager;.unregisterReceiver (Landroid/content/BroadcastReceiver;)V
  07-03 20:23:39.674: D/dalvikvm(25239): VFY: replacing opcode 0x6e at 0x0004
  07-03 20:23:39.674: I/dalvikvm(25239): Could not find method android.support.v4.content.LocalBroadcastManager.registerReceiver, referenced from method com.facebook.UiLifecycleHelper.onResume
  07-03 20:23:39.674: W/dalvikvm(25239): VFY: unable to resolve virtual method 836: Landroid/support/v4/content/LocalBroadcastManager;.registerReceiver (Landroid/content/BroadcastReceiver;Landroid/content/IntentFilter;)V
  07-03 20:23:39.674: D/dalvikvm(25239): VFY: replacing opcode 0x6e at 0x0032
  07-03 20:23:39.674: D/AndroidRuntime(25239): Shutting down VM
  07-03 20:23:39.674: W/dalvikvm(25239): threadid=1: thread exiting with uncaught exception (group=0x41abeba8)
  07-03 20:23:39.684: E/AndroidRuntime(25239): FATAL EXCEPTION: main
  07-03 20:23:39.684: E/AndroidRuntime(25239): Process: com.example.braucamkopa, PID: 25239
  07-03 20:23:39.684: E/AndroidRuntime(25239): java.lang.NoClassDefFoundError: android.support.v4.content.LocalBroadcastManager
  07-03 20:23:39.684: E/AndroidRuntime(25239):    at com.facebook.UiLifecycleHelper.&lt;init&gt;(UiLifecycleHelper.java:72)
  07-03 20:23:39.684: E/AndroidRuntime(25239):    at com.example.braucamkopa.MainLogin.onCreate(MainLogin.java:33)
  07-03 20:23:39.684: E/AndroidRuntime(25239):    at android.app.Activity.performCreate(Activity.java:5231)
  07-03 20:23:39.684: E/AndroidRuntime(25239):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
  07-03 20:23:39.684: E/AndroidRuntime(25239):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)
  07-03 20:23:39.684: E/AndroidRuntime(25239):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
  07-03 20:23:39.684: E/AndroidRuntime(25239):    at android.app.ActivityThread.access$800(ActivityThread.java:135)
  07-03 20:23:39.684: E/AndroidRuntime(25239):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
  07-03 20:23:39.684: E/AndroidRuntime(25239):    at android.os.Handler.dispatchMessage(Handler.java:102)
  07-03 20:23:39.684: E/AndroidRuntime(25239):    at android.os.Looper.loop(Looper.java:136)
  07-03 20:23:39.684: E/AndroidRuntime(25239):    at android.app.ActivityThread.main(ActivityThread.java:5001)
  07-03 20:23:39.684: E/AndroidRuntime(25239):    at java.lang.reflect.Method.invokeNative(Native Method)
  07-03 20:23:39.684: E/AndroidRuntime(25239):    at java.lang.reflect.Method.invoke(Method.java:515)
  07-03 20:23:39.684: E/AndroidRuntime(25239):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
  07-03 20:23:39.684: E/AndroidRuntime(25239):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
  07-03 20:23:39.684: E/AndroidRuntime(25239):    at dalvik.system.NativeStart.main(Native Method)
  07-03 20:27:55.754: I/Process(25937): Sending signal. PID: 25937 SIG: 9
  07-03 20:34:58.184: I/Process(26488): Sending signal. PID: 26488 SIG: 9
  </code></pre>
  
  <p>It seems to me that i've tried everything, so now I must ask you guys..
  Please help me out, i'm loosing my mind here!</p>
  
  <p><strong>FIXED</strong> Fixed this error by fixing dependencies (3 different versions of android_support-v4.jar - wtf to that!) after that fixed build path by deleting the duplicates and finally clean/rebuild. Thanks for pointing in the right direction.</p>