反应本机 fbsdk 设置构建错误

react native fbsdk setup build errors

我已经完成了link and also this link中给出的所有设置。但是当我尝试 运行 我的项目时出现以下错误,

/mnt/2EB2BF06B2BED217/Freelancing/yasco/sg/saZen/mobile/sazenappmobile/SaZen/android/app/src/main/java/com/sazen/MainActivity.java:17: error: cannot find symbol
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
                                                                  ^
  symbol:   class Intent
  location: class MainActivity
/mnt/2EB2BF06B2BED217/Freelancing/yasco/sg/saZen/mobile/sazenappmobile/SaZen/android/app/src/main/java/com/sazen/MainApplication.java:11: error: cannot find symbol
import com.facebook.CallbackManager;
                   ^
  symbol:   class CallbackManager
  location: package com.facebook
/mnt/2EB2BF06B2BED217/Freelancing/yasco/sg/saZen/mobile/sazenappmobile/SaZen/android/app/src/main/java/com/sazen/MainApplication.java:12: error: cannot find symbol
import com.facebook.FacebookSdk;
                   ^
  symbol:   class FacebookSdk
  location: package com.facebook
/mnt/2EB2BF06B2BED217/Freelancing/yasco/sg/saZen/mobile/sazenappmobile/SaZen/android/app/src/main/java/com/sazen/MainApplication.java:13: error: package com.facebook.reactnative.androidsdk does not exist
import com.facebook.reactnative.androidsdk.FBSDKPackage;
                                          ^
/mnt/2EB2BF06B2BED217/Freelancing/yasco/sg/saZen/mobile/sazenappmobile/SaZen/android/app/src/main/java/com/sazen/MainApplication.java:14: error: package com.facebook.appevents does not exist
import com.facebook.appevents.AppEventsLogger;
                             ^
/mnt/2EB2BF06B2BED217/Freelancing/yasco/sg/saZen/mobile/sazenappmobile/SaZen/android/app/src/main/java/com/sazen/MainApplication.java:21: error: cannot find symbol
  private static CallbackManager mCallbackManager = CallbackManager.Factory.create();
                 ^
  symbol:   class CallbackManager
  location: class MainApplication
/mnt/2EB2BF06B2BED217/Freelancing/yasco/sg/saZen/mobile/sazenappmobile/SaZen/android/app/src/main/java/com/sazen/MainApplication.java:23: error: cannot find symbol
  protected static CallbackManager getCallbackManager() {
                   ^
  symbol:   class CallbackManager
  location: class MainApplication
/mnt/2EB2BF06B2BED217/Freelancing/yasco/sg/saZen/mobile/sazenappmobile/SaZen/android/app/src/main/java/com/sazen/MainApplication.java:21: error: package CallbackManager does not exist
  private static CallbackManager mCallbackManager = CallbackManager.Factory.create();
                                                                   ^
/mnt/2EB2BF06B2BED217/Freelancing/yasco/sg/saZen/mobile/sazenappmobile/SaZen/android/app/src/main/java/com/sazen/MainApplication.java:38: error: cannot find symbol
          new FBSDKPackage(mCallbackManager)
              ^
  symbol: class FBSDKPackage
/mnt/2EB2BF06B2BED217/Freelancing/yasco/sg/saZen/mobile/sazenappmobile/SaZen/android/app/src/main/java/com/sazen/MainApplication.java:52: error: cannot find symbol
    FacebookSdk.sdkInitialize(getApplicationContext());
    ^
  symbol:   variable FacebookSdk
  location: class MainApplication
/mnt/2EB2BF06B2BED217/Freelancing/yasco/sg/saZen/mobile/sazenappmobile/SaZen/android/app/src/main/java/com/sazen/MainApplication.java:54: error: cannot find symbol
    AppEventsLogger.activateApp(this);
    ^
  symbol:   variable AppEventsLogger
  location: class MainApplication
11 errors
:app:compileDebugJavaWithJavac FAILED

目前我正在使用“16.0.0-alpha.12”版本的反应。

如果您使用的是最新的 react-native 降级到 0.46.4,最新版本有一些影响许多原生包的重大变化。

同时使用 react-native-fbsdk@0.6.0,因为它仍然使用 buildToolsVersion 23 编译

再次按照步骤操作,应该可以了

我最近花了好几个小时来尝试完成这项工作,只有降级到这些版本才能解决我遇到的问题。

我的 gradle 的最终版本对我有用,如下所示,

android {
    compileSdkVersion 24
...
repositories {
    mavenCentral()
}

dependencies {
    compile project(':react-native-fbsdk')
    compile fileTree(dir: "libs", include: ["*.jar"])
    compile "com.android.support:appcompat-v7:24.2.1"
    compile "com.facebook.react:react-native:+"  // From node_modules
    compile 'com.facebook.android:facebook-android-sdk:[4,5)'
}

在依赖项中观察这些行,

dependencies {
    compile "com.android.support:appcompat-v7:24.2.1"
    compile 'com.facebook.android:facebook-android-sdk:[4,5)'

并且 compileSDKVersion 必须与支持相同,因此它必须是,

android {
    compileSdkVersion 24

这些是让我坚持了这么多天的主要事情。

我的项目使用最新的包版本编译,使用 buildToolsVersion 25.0.3

build.gradle

compileSdkVersion 25
buildToolsVersion "25.0.3"

build.gradle 默认配置

targetSdkVersion 25

build.gradle 依赖关系

compile "com.android.support:appcompat-v7:25.0.3"

文档说

If your react-native version is below 0.29.0

但是它抛出错误说找不到符号 Intent 所以...

MainActivity.java

import android.content.Intent;

您需要在 MainActivity.java 中导入 android.content.Intent:

import android.content.Intent;

在MainApplication.java中:

import com.facebook.CallbackManager;
import com.facebook.reactnative.androidsdk.FBSDKPackage;
import com.facebook.appevents.AppEventsLogger;
import com.facebook.FacebookSdk;