反应原生fbsdk设置构建错误

时间:2017-08-08 03:48:02

标签: android facebook react-native fbsdk react-native-fbsdk

我已完成此link以及此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”版本的反应。

4 个答案:

答案 0 :(得分:3)

我的项目使用buildToolsVersion 25.0.3

编译最新的软件包版本

的build.gradle

compileSdkVersion 25
buildToolsVersion "25.0.3"

build.gradle defaultConfig

targetSdkVersion 25

build.gradle依赖项

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

文档说

  

如果您的react-native版本低于0.29.0

但它会抛出错误,说无法找到符号意图......

MainActivity.java

import android.content.Intent;

答案 1 :(得分:1)

如果您使用最新的react-native降级到0.46.4,则最新版本会有一些影响许多本机程序包的重大更改。

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

再次按照步骤进行操作

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

答案 2 :(得分:1)

您需要在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;

答案 3 :(得分:0)

我的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

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