Android、Facebook 登录按钮导致崩溃 (SDK 4.0.0)

Android, Facebook Login Button Causes Crash (SDK 4.0.0)

在我的 activity .xml 文件中,我包含了 Facebook 登录按钮(来自 this 文档)

    <com.facebook.login.widget.LoginButton
    android:id="@+id/login_button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center_horizontal"
    android:layout_marginTop="30dp"
    android:layout_marginBottom="30dp" />

我立即收到警告说

The following classes could not be found:
    - com.facebook.login.widget.LoginButton

文档说

Add the button to your layout XML file with the full class name, com.facebook.widget.LoginButton

但是更改顶行没有任何作用。应用直接闪退,打不开,log cat什么也没有记录(外接设备测试)

删除按钮,或将其更改为

    <Button
    android:id="@+id/login_button"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center_horizontal"
    android:layout_marginTop="30dp"
    android:layout_marginBottom="30dp" />

停止崩溃,但这是我第一次使用 Facebook SDK,不知道常规按钮是否有效。

提前致谢。

在膨胀视图之前添加 FacebookSdk.sdkInitialize(getActivity().getApplicationContext());..
- 如果这个xml用在activity,在setContentView()之前写上一行
-如果这个xml用在fragment中,把这行写在inflater.inflate...

之前

并且,忽略布局预览中显示的警告 window