简体   繁体   English

React Native Facebook SDK 在 Android 上初始化

[英]React Native Facebook SDK Initialization on Android

I am integrating the Faecbook SDK into an existing react-native project and having the dreaded error: The SDK has not been initialized, make sure to call FacebookSdk.sdkInitialize() first.我正在将 Faecbook SDK 集成到现有的 react-native 项目中并出现可怕的错误: The SDK has not been initialized, make sure to call FacebookSdk.sdkInitialize() first.

I have followed the instructions carefully, so strings.xml contains:我已仔细按照说明进行操作,因此 strings.xml 包含:

<string name="facebook_app_id">xxxxx</string>

And in AndroidManifest.xml, inside the application element, I have在 AndroidManifest.xml 中,在应用程序元素中,我有

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

I've made the changes to settings.gradle and build.xml as described.我已经按照描述对 settings.gradle 和 build.xml 进行了更改。

All the instructions say that I shouldn't need to call FacebookSdk.sdkInitialize() if I have done the above.所有的说明都说如果我完成了上述操作,我不需要调用FacebookSdk.sdkInitialize() I'm using react-native-fbsdk version 1.1.1 and react native 0.60.5我正在使用 react-native-fbsdk 版本 1.1.1 和 react native 0.60.5

When I followed the instructions on a simple new react-native project it works, so I am wondering if it is a conflict with something in the app, but I'm not sure what to look for.当我按照一个简单的新 react-native 项目的说明进行操作时,它可以工作,所以我想知道它是否与应用程序中的某些内容发生冲突,但我不确定要寻找什么。 Can anyone suggest how to debug?谁能建议如何调试?

Thanks.谢谢。

In case it helps anyone else, I found the culprit by creating a vanilla react-native app with fbsdk integration and painstakingly copying in config from my real app until the facebook integration stopped working.如果它对其他人有帮助,我通过创建一个带有 fbsdk 集成的香草 react-native 应用程序并煞费苦心地从我的真实应用程序复制配置直到 facebook 集成停止工作,从而找到了罪魁祸首。

It turns out that removing tools:node="replace" from the application element in AndroidManifest.xml fixed the problem.事实证明,从 AndroidManifest.xml 中的应用程序元素中删除tools:node="replace"解决了这个问题。

<application
 ...
 tools:node="replace">

(I'm not sure why this attribute had been added, the git commit message from the developer who added it was enigmatic and the app still seems to work without it...) (我不确定为什么要添加这个属性,来自添加它的开发人员的 git 提交消息是神秘的,没有它应用程序似乎仍然可以工作......)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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