Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ios version of app works, but Android fails due to no suitable constructor found for AccessToken for React Native App

As mentioned in the title, the Ios version of this app works fine on a physical device. However, when I try to build it on an android device, I get an error

error: no suitable constructor found for AccessToken(String,String,String,<null>,<null>,<null>,<null>,<null>)
constructor AccessToken.AccessToken(String,String,String,Collection<String>,Collection<String>,AccessTokenSource,Date,Date,Date) is not applicable
(actual and formal argument lists differ in length)
constructor AccessToken.AccessToken(Parcel) is not applicable
(actual and formal argument lists differ in length)

This error is highlighted in FBGraphRequestModule.java file, specifically in this method

    private void setConfig(GraphRequest graphRequest, ReadableMap configMap) {
            if (configMap == null) {
                graphRequest.setAccessToken(AccessToken.getCurrentAccessToken());
                return;
            }
            if (configMap.hasKey("parameters")) {
                graphRequest.setParameters(buildParameters(configMap.getMap("parameters")));
            }
            if (configMap.hasKey("httpMethod")) {


graphRequest.setHttpMethod(HttpMethod.valueOf(configMap.getString("httpMethod")));
    }
    if (configMap.hasKey("version")) {
        graphRequest.setVersion(configMap.getString("version"));
    }
    if (configMap.hasKey("accessToken")) {
        graphRequest.setAccessToken(new AccessToken(
            configMap.getString("accessToken"),
            AccessToken.getCurrentAccessToken().getApplicationId(),
            AccessToken.getCurrentAccessToken().getUserId(),
            null,
            null,
            null,
            null,
            null));
    } else {
        graphRequest.setAccessToken(AccessToken.getCurrentAccessToken());
    }
}

More specifically,

if (configMap.hasKey("accessToken")) {
            graphRequest.setAccessToken(new AccessToken(
                configMap.getString("accessToken"),
                AccessToken.getCurrentAccessToken().getApplicationId(),
                AccessToken.getCurrentAccessToken().getUserId(),
                null,
                null,
                null,
                null,
                null));

My Java skills are nonexistent, so I have no idea how to fix this problem.

like image 382
VK1 Avatar asked Dec 01 '22 14:12

VK1


2 Answers

I had the same issue today as well, upgrading react-native-fbsdk to 0.8.0 seems to fix it

like image 165
Ahmed Kotb Avatar answered Dec 03 '22 05:12

Ahmed Kotb


I had also that issue today and solved by modifying the package to have the last parameter - dataAccessExpirationTime.

new AccessToken(
            configMap.getString("accessToken"),
            AccessToken.getCurrentAccessToken().getApplicationId(),
            AccessToken.getCurrentAccessToken().getUserId(),
            null,
            null,
            null,
            null,
            null,
            null)

You will see this issue in FBGraphRequestModule.java and Utility.java file. So please fix both files.

like image 31
Lee ChienHui Avatar answered Dec 03 '22 03:12

Lee ChienHui