Facebook setInitialize已弃用,但删除它会导致充气错误

时间:2017-09-10 09:56:27

标签: android facebook facebook-android-sdk

正如这里建议的那样:

  

Facebook SDK现在已在应用程序启动时自动初始化。如果你   在主要过程中使用Facebook SDK而不需要   SDK初始化完成后回调你现在可以删除对它的调用   FacebookSDK.sdkInitialize。如果你确实需要回调,你应该   手动调用代码中的回调。

Facebook.setInitalizer(context)现已弃用。问题是,当我按照建议删除该行:Facebook.setInitalizer(context)时,我发现了一个充气错误:com.facebook.login.widget.LoginButton

<com.facebook.login.widget.LoginButton
    android:id="@+id/signin_activity_login_button_fb"
    android:layout_width="240dp"
    android:layout_height="wrap_content"
    ...
/>

错误:

android.view.InflateException: Binary XML file line #22: Binary XML file line #22: Error inflating class com.facebook.login.widget.LoginButton

当我返回初始化器时,错误消失了。我该怎么办。

同时Gradle:

compile 'com.facebook.android:facebook-android-sdk:[4,5)'

1 个答案:

答案 0 :(得分:0)

当我使用Firebase身份验证时,我也遇到了同样的问题。但是,我现在解决了这个问题。

第1步:点击&#34; SDK Manager&#34;按钮并下载最新版本的Google Play服务。 enter image description here

步骤2:然后,点击&#34; build.gradle(模块:应用)&#34;并更新谷歌的这些依赖关系以对齐版本号是&#34; 12.0.1&#34;然后点击&#34;同步&#34;。

<Table pagination={false}>

步骤3:检查这些代码已经在您的AndroidManifest.xml中

implementation 'com.google.firebase:firebase-auth:12.0.1'
implementation 'com.google.firebase:firebase-database:12.0.1'
compile 'com.google.firebase:firebase-auth:12.0.1'
compile 'com.google.firebase:firebase-core:12.0.1'
compile 'com.google.android.gms:play-services-ads:12.0.1'

第4步:创建&#34; ids.xml&#34;该目录中的文件。文件路径:app / res / values / ids.xml

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

Step4:不要关心已弃用的消息。只需将它保存在您的活动中即可。

<?xml version="1.0" encoding="utf-8"?>
<resources>

<!--
    Your Facebook App ID. See README.
-->
<!--  TODO(developer): REPLACE -->
<string name="facebook_app_id">REPLACE_ME</string>

<!--
  Your Twitter Key and Secret, see README.
-->
<!-- TODO(developer): REPLACE -->
<string name="twitter_consumer_key">REPLACE_ME</string>
<string name="twitter_consumer_secret">REPLACE_ME</string>
</resources>