0

I am trying to set a Facebook AccessToken in React Native on an Android device via the function AccessToken.setCurrentAccessToken(...);

And I am getting the following error:

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>

I am not sure why it cannot find the Constructor, as the types match the definition in the docs: https://developers.facebook.com/docs/reference/android/current/class/AccessToken , and the build compiles, so the types match the definition that's expected...

The React Native code I'm running to generate this error is:

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

I have these entries in my app/build.gradle:

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

and these in MainApplication.java:

     new FBSDKPackage(mCallbackManager),

and

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

This in settings.gradle:

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

I feel as though my build environment uses one JAR, and my runtime has a different one, as there appears to be a 'newer' AccessToken class defined here: https://developers.facebook.com/docs/reference/androidsdk/current/facebook/com/facebook/accesstoken.html/ , but I cannot identify which is actually used at runtime to investigate further. Any suggestions as to where/how to investigate this will be gratefully received.

This code has worked in the past...

[Edit....]

Project's 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'
            }
        }
    }
}

[Edit 2...]

Also, JS code / React Native code works fine on iOS, so its an Android specific issue...

Henry Bevan
  • 314
  • 2
  • 8
  • I know it doesn't seem related, But maybe this will help: https://stackoverflow.com/a/52944600/4255978 – HedeH Nov 01 '18 at 11:57
  • Check your project `/node_modules/react-native-fbsdk/android/src/main/java/com/facebook/reactnative/androidsdk/FBAccessTokenModule.java` has the method setCurrentAccessToken. – Asha Nov 01 '18 at 13:07
  • It does, it 'breaks' at line 64 in Utility.java (https://github.com/facebook/react-native-fbsdk/blob/master/android/src/main/java/com/facebook/reactnative/androidsdk/Utility.java), via line 67 in FBAccessTokenModule.java (https://github.com/facebook/react-native-fbsdk/blob/master/android/src/main/java/com/facebook/reactnative/androidsdk/FBAccessTokenModule.java) – Henry Bevan Nov 01 '18 at 14:23

0 Answers0