简体   繁体   中英

Error: Class not found when unmarshalling: com.facebook.login.Login Client Request

I am getting this error when hitting the "Login With Facebook" (Simple login button).

I have Google, and read other topics here - but I can not see any thing matching my issue.

I am adding Login.java class below.

public class Login extends Activity {



/**
 * Called when the activity is first created.
 */

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    FacebookSdk.sdkInitialize(getApplicationContext());
    setContentView(R.layout.activity_login);
    CallbackManager callbackManager = CallbackManager.Factory.create();
    LoginButton loginButton = (LoginButton) findViewById(R.id.login_button);
    loginButton.setReadPermissions("public_profile", "email", "user_friends");

    // Other app specific specialization

    loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {


        @Override
        public void onSuccess(LoginResult loginResult) {

            Log.i("Login", "Logged in: ");
          Intent i = new Intent(Login.this, MainActivity.class);
            startActivity(i);
        }

        @Override
        public void onCancel() {
            // App code

        }

        @Override
        public void onError(FacebookException exception) {
            // App code
            Log.i("Error" , "Error");
        }


    });
}
}

StackTrace:

  05-28 20:07:27.550 872-1363/? E/Parcel﹕ Class not found when unmarshalling: com.facebook.login.LoginClient$Request java.lang.ClassNotFoundException: com.facebook.login.LoginClient$Request at java.lang.Class.classForName(Native Method) at java.lang.Class.forName(Class.java:308) at java.lang.Class.forName(Class.java:272) at android.os.Parcel.readParcelableCreator(Parcel.java:2275) at android.os.Parcel.readParcelable(Parcel.java:2239) at android.os.Parcel.readValue(Parcel.java:2146) at android.os.Parcel.readArrayMapInternal(Parcel.java:2479) at android.os.BaseBundle.unparcel(BaseBundle.java:221) at android.os.BaseBundle.getString(BaseBundle.java:918) at android.content.Intent.getStringExtra(Intent.java:5378) at com.android.server.am.ActivityStackSupervisor.startActivityLocked(ActivityStackSupervisor.java:1768) at com.android.server.am.ActivityStackSupervisor.startActivityMayWait(ActivityStackSupervisor.java:1313) at com.android.server.am.ActivityManagerService.startActivityAsUser(ActivityManagerService.java:4522) at com.android.server.am.ActivityManagerService.startActivity(ActivityManagerService.java:4368) at android.app.ActivityManagerNative.onTransact(ActivityManagerNative.java:140) at com.android.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:2964) at android.os.Binder.execTransact(Binder.java:446) Caused by: java.lang.ClassNotFoundException: Didn't find class "com.facebook.login.LoginClient$Request" on path: DexPathList[[directory "."],nativeLibraryDirectories=[/vendor/lib, /system/lib]] at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56) at java.lang.ClassLoader.loadClass(ClassLoader.java:511) at java.lang.ClassLoader.loadClass(ClassLoader.java:469)            at java.lang.Class.classForName(Native Method)            at java.lang.Class.forName(Class.java:308)            at java.lang.Class.forName(Class.java:272)            at android.os.Parcel.readParcelableCreator(Parcel.java:2275)            at android.os.Parcel.readParcelable(Parcel.java:2239)            at android.os.Parcel.readValue(Parcel.java:2146)            at android.os.Parcel.readArrayMapInternal(Parcel.java:2479)            at android.os.BaseBundle.unparcel(BaseBundle.java:221)            at android.os.BaseBundle.getString(BaseBundle.java:918)            at android.content.Intent.getStringExtra(Intent.java:5378)            at com.android.server.am.ActivityStackSupervisor.startActivityLocked(ActivityStackSupervisor.j Java:1768)      at com.android.server.am.ActivityStackSupervisor.startActivityMayWait(ActivityStackSupervisor.java:1313) at com.android.server.am.ActivityManagerService.startActivityAsUser(ActivityManagerService.java:4522)            at com.android.server.am.ActivityManagerService.startActivity(ActivityManagerService.java:4368)            at android.app.ActivityManagerNative.onTransact(ActivityManagerNative.java:140)            at com.android.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:2964)            at android.os.Binder.execTransact(Binder.java:446) Suppressed: java.lang.ClassNotFoundException: com.facebook.login.LoginClient$Request at java.lang.Class.classForName(Native Method) at java.lang.BootClassLoader.findClass(ClassLoader.java:781) at java.lang.BootClassLoader.loadClass(ClassLoader.java:841) at java.lang.ClassLoader.loadClass(ClassLoader.java:504) ... 18 more Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available 

Check your android:noHistory flag on the activity.

See link https://developers.facebook.com/bugs/1621984714705591/ look for post by Andreas Bergenwall

This can happen when the user has the native Facebook App installed.

You can suppress the attempt to open it by initializing the LoginManager 's LoginBehaviour :

 // Don't allow the Facebook App to open.
 LoginManager.getInstance().setLoginBehavior(LoginBehavior.WEB_VIEW_ONLY);

I too had this issue. Mine however was a login call made within the FBActivity.OnResume method for callbacks to login after accepting fb perms.

I simply moved the request into the profile tracker in the onCreate method

    ProfileTracker profileTracker = new ProfileTracker() {
        @Override
        protected void onCurrentProfileChanged(Profile oldProfile, Profile currentProfile) {

            Profile.fetchProfileForCurrentAccessToken();
            if(currentProfile != null) {
                String fbUserId = currentProfile.getId();
                profileUrl = currentProfile.getProfilePictureUri(200, 200).toString();
                Log.d("FB profile", "got new/updated profile from thread " + fbUserId);

                // jump if logged in already
                GetFacebookProfileAndJump(currentProfile);

            }

        }
    };

Also ensure your OnCreate super is as follows

    FacebookSdk.sdkInitialize(getApplicationContext());
    mCallbackmanager = CallbackManager.Factory.create();
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_fbauth_);

...

You should add this to your acctivity

    @Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)            {
    super.onActivityResult(requestCode, resultCode, data);
    callbackManager.onActivityResult(requestCode, resultCode, data);

}

but if your using parse SDK add this

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    ParseFacebookUtils.onActivityResult(requestCode, resultCode, data);
}

I had the same problem, and solved by putting the facebook_app_id to strings.xml instead of a constant:

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

In my case i forgot to add application package name and class name on the developer page of facebook. After i added this information then it worked.

I have struggled with this problem and I fixed with multidex enabled

add this in your build file

multiDexEnabled true

also this code in your activity

@Override   
protected void attachBaseContext(Context context) {
         super.attachBaseContext(context);
         MultiDex.install(this);
}

after adding this in your build gradle dependencies

compile 'com.android.support:multidex:1.0.1'

Actually this is happend. Because of the onActivityResult method has not implemented in side your Activity and also you must call

callbackManager.onActivityResult(requestCode, resultCode, data);

method inside this method. I am sure 100% your problem resolved.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM