无法在Android上的React Native中设置当前的Facebook AccessToken

时间:2018-11-01 11:38:08

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

我正在尝试通过功能AccessToken.setCurrentAccessToken(...);在Android设备上的React Native中设置Facebook AccessToken

我收到以下错误:

E/unknown:ReactNative: Exception in native call
    java.lang.RuntimeException: Could not invoke FBAccessToken.setCurrentAccessToken
        at com.facebook.react.bridge.JavaMethodWrapper.invoke(JavaMethodWrapper.java:383)
        <snip>
     Caused by: java.lang.reflect.InvocationTargetException
        at java.lang.reflect.Method.invoke(Native Method)
        at com.facebook.react.bridge.JavaMethodWrapper.invoke(JavaMethodWrapper.java:372)
        <snip> 
     Caused by: java.lang.NoSuchMethodError: No direct method <init>(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/util/Collection;Ljava/util/Collection;Lcom/facebook/AccessTokenSource;Ljava/util/Date;Ljava/util/Date;)V in class Lcom/facebook/AccessToken; or its super classes (declaration of 'com.facebook.AccessToken' appears in /data/app/<app-name-here>/base.apk)
        at com.facebook.reactnative.androidsdk.Utility.buildAccessToken(Utility.java:90)
        at com.facebook.reactnative.androidsdk.FBAccessTokenModule.setCurrentAccessToken(FBAccessTokenModule.java:69)
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.facebook.react.bridge.JavaMethodWrapper.invoke(JavaMethodWrapper.java:372) 
        <snip>

我不确定为什么找不到构造器,因为类型与文档中的定义匹配:https://developers.facebook.com/docs/reference/android/current/class/AccessToken ,并且编译完成,因此类型匹配预期的定义...

我正在运行以生成此错误的React Native代码是:

AccessToken.getCurrentAccessToken().then((ffff) => {
    AccessToken.setCurrentAccessToken(ffff);
})

我的app/build.gradle中有以下条目:

implementation 'com.facebook.android:facebook-android-sdk:[4,5)'
implementation project(':react-native-fbsdk')

以及MainApplication.java中的这些:

     new FBSDKPackage(mCallbackManager),

    private static CallbackManager mCallbackManager = 
        CallbackManager.Factory.create();

settings.gradle中的内容:

include ':react-native-fbsdk'
project(':react-native-fbsdk').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-fbsdk/android')

我觉得我的构建环境使用了一个JAR,而我的运行时使用了一个不同的JAR,因为这里定义了一个{new} AccessToken类:https://developers.facebook.com/docs/reference/androidsdk/current/facebook/com/facebook/accesstoken.html/,但是我无法确定实际使用的是哪个在运行时进行进一步调查。有关在何处/如何进行调查的任何建议将不胜感激。

此代码过去一直有效...

[编辑......]

项目的build.gradle

buildscript {
    repositories {
        jcenter()
        maven {
            url 'https://maven.fabric.io/public'
        }
        mavenCentral()
        google()
        maven {
            url "https://maven.google.com"
        }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.1'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
        classpath 'com.google.gms:google-services:4.0.1'

        // The Fabric Gradle plugin uses an open ended version to react
        // quickly to Android tooling updates
        classpath 'io.fabric.tools:gradle:1.+'

        // svg to png
        classpath('fr.avianey.androidsvgdrawable:gradle-plugin:3.0.0') {
            // should be excluded to avoid conflict
            exclude group: 'xerces'
        }
    }
}

allprojects {
    repositories {
        mavenLocal()
        google()
        jcenter()
        maven {
            // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
            url "$rootDir/../node_modules/react-native/android"
        }
        maven { url 'https://maven.fabric.io/public' }
        // jitpack repo is necessary to fetch ucrop dependency
        maven { url "https://jitpack.io" }
    }
}

subprojects {
    afterEvaluate {project ->
        if (project.hasProperty("android")) {
            android {
                compileSdkVersion 27
                buildToolsVersion '27.0.3'
            }
        }
    }
}

[编辑2 ...]

此外,JS代码/ React Native代码在iOS上运行良好,因此它是Android特有的问题...

0 个答案:

没有答案