4

但是,当应用程序启动并且应该创建 Facebook 会话时,应用程序崩溃了我认为这些库没有包含在构建中......

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);
  }

}

这是异常堆栈:

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
4

2 回答 2

14

只需更换

     YourProject\lib\android-support-v4.jar 

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

其中 x.xx.x 是 facebook sdk 版本,例如 3.21.0

于 2014-03-04T15:04:48.963 回答
0

尝试在棒棒糖之前的 Android 版本上运行我的应用程序时遇到了同样的问题。经过数小时的搜索和使用库后,我认为这只是因为棒棒糖之前版本的 65k 功能限制。

So before trying the above solution or any other solution, I recommend moving the facebook sdk initialize call later in the code and not in the onCreate method. In this way, if the issue was because of the 65k limit, you might get a NoClassDef found exception for another class.

To fix the 65k limit issue, just go through your libraries in build.gradle and remove any unused libraries. Also use just what is needes from the Google apis, especially Google play services. It will also help cleanup your app and reduce file size.

于 2016-01-06T22:24:45.663 回答