嘿,我知道以前有人问过这个问题,但似乎没有一个解决方案有帮助。我在我的应用程序中第一次使用 Facebook SDK。
我尝试过的:
我已经尝试过大部分在Internet但没有得到任何关于此事的信息。
这是我的 MainActivity.java:
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
FacebookSdk.sdkInitialize(getApplicationContext());
}
}
这是我的 Activity_main.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:facebook="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<com.facebook.login.widget.LoginButton
android:id="@+id/connectWithFbButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_gravity="center_horizontal"
android:text=" connect_with_facebook" />
</LinearLayout>
see my Logcat:
05-13 16:30:39.332: E/AndroidRuntime(10264): Caused by: The SDK has not been initialized, make sure to call FacebookSdk.sdkInitialize() first.
Problem
在为react-native项目集成Android SDK时,我已经完成了Android with React Native v0.30+ 项目配置 https://developers.facebook.com/docs/react-native/configure-android-current指导,然后跑react-native run-android
然后得到这个屏幕:
我了解到FacebookSdk.sdkInitialize
已弃用。see here https://developers.facebook.com/docs/reference/androidsdk/current/facebook/com/facebook/facebooksdk.html/#sdkinitialize-context-int-
经过一番搜索,我意识到该指南不包含为我的应用程序添加 Facebook 应用程序 ID 的步骤。
Solution
-
Open android/app/src/main/AndroidManifest.xml
文件并查看<application>
标签以确认这一点meta-data
标签存在:
<meta-data android:name="com.facebook.sdk.ApplicationId"
android:value="@string/facebook_app_id"/>
-
Open android/app/src/main/res/values/strings.xml
文件并确认有一个“facebook_app_id”字符串标记,其值为您的应用程序 ID:
<string name="facebook_app_id">YOUR_APP_ID_HERE</string>
Run react-native run-android
.
这些是对我有用的步骤。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)