Facebook Android SDK v4.0.0 ShareDialog NullPointerException issue

耗尽温柔 提交于 2019-12-01 05:24:42

You also need to add the application id like this:

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

(hopefully someone at FB will read this)

In addition to the (correct) advice given by Gokhan Caglar, also note this: Do not write the app-id number directly into AndroidManifest.xml! For FB to work, app-id must also be defined properly according to best practice in the file strings.xml

Because the app-id is also used under the provider tag, but there directly as the number, I did the shortcut of writing the app-id number directly into the meta-data tag as well. Huge mistake, 2 days gone.

As it seems, FB will make use of app-id fetched from both AndroidManifest.xml and directly based on the definitions in strings.xml. Both must be there. app-id must be defined in strings.xml. This solved the issue.

For FB development team, a couple of suggestions that will save people’s time:

  • Either remove this over-stringent use of app-id, or explain in the tutorial that this is the only way. (It is more stringent than Android itself)

  • Make a better error reporting system as overlay when the app definitions are not proper. A null exception like this deep within FB soon becomes your time thief of the day. In this case, an error report of the type: ”Error: app-id not defined in strings.xml” would have been satisfactory.

  • Regarding the tutorial, it contains a trap also, and so I mention it: If you run the tutorial here: https://developers.facebook.com/quickstarts/?platform=android, after you have already inserted key hash for development, something you would easily do if things aren’t working, then be aware that this tutorial will delete (or rather replace) vital info in the app definition without telling you about it. Since you have perhaps already defined the keyhash, you do not fill it in once again in this quickstart guide. Hence, later you discover that the keyhash is gone and wonder why.

do not write the facebook key within the meta

write it in a string and reference it in the meta in manifest

like so

<string name="id_facebook">id_facebook</string>

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

hope this helps :)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!