darwin-morocho / flutter-facebook-auth

A flutter plugin to add login with facebook in your flutter app
193 stars 127 forks source link

Not working on Android #9

Closed sallypeters closed 3 years ago

sallypeters commented 3 years ago

Hi there - thanks for this great plugin. It works perfectly for me in iOS but in Android, I get an error when I try and run the same code :

var result = await FacebookAuth.instance.login(permissions: [ 'email' ]);

This is the error :

Attempt to invoke interface method 'android.app.Activity io.flutter.embedding.engine.plugins.activity.ActivityPluginBinding.getActivity()' on a null object reference

I have Flutter 1.12.13 hotfix 5.

I'm assuming this is because the Plugin is attempting to use Native embedding ?

I believe I have followed exactly the requirements including:

  1. Adding package and activity name in developer.facebook.com
  2. Updating Strings.xml with facebook app id etc
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">My great app</string>
<string name="facebook_app_id">app id</string>
<string name="fb_login_protocol_scheme">fb[app id]</string>
</resources>
  1. Update Manifest file with intent filter etc

    
    
        <meta-data android:name="com.facebook.sdk.ApplicationId" 
    android:value="@string/facebook_app_id"/>

<activity android:name="com.facebook.FacebookActivity" android:configChanges= "keyboard|keyboardHidden|screenLayout|screenSize|orientation" android:label="@string/app_name" />

<activity android:name="com.facebook.CustomTabActivity" android:exported="true">



Is there something else I am missing for Android ?
sallypeters commented 3 years ago

The issue is to do with new changes to Flutter apps that were flutter create d prior to version 1.12.

I notice in your manifest you are using :


<meta-data
            android:name="flutterEmbedding"
            android:value="2" />

This is new and will mean that the old platform wrappers hosting the runtime at io.flutter.app.FlutterActivity are deprecated and to be replaced with : io.flutter.embedding.android.FlutterActivity

In order to use your plugin for Android, the only thing that can be done is to move the Flutter Activity over to using the new embedding.android activity and to make the necessary changes to Android manifest - thus there is no need to manually register plugins with :

GeneratedPluginRegistrant.registerWith(this);

as registration will happen automatically when FlutterEngine gets created.

I've made the necessary changes and can confirm your plugin works as expected in Android. My original Splash screen code no longer works but thats another matter and not related to your plugin.

Also - Just to confirm, I'm assuming this plugin DOES NOT USE UIWebView on the iOS side ?

Thanks

darwin-morocho commented 3 years ago

The issue is to do with new changes to Flutter apps that were flutter create d prior to version 1.12.

I notice in your manifest you are using :


<meta-data
            android:name="flutterEmbedding"
            android:value="2" />

This is new and will mean that the old platform wrappers hosting the runtime at io.flutter.app.FlutterActivity are deprecated and to be replaced with : io.flutter.embedding.android.FlutterActivity

In order to use your plugin for Android, the only thing that can be done is to move the Flutter Activity over to using the new embedding.android activity and to make the necessary changes to Android manifest - thus there is no need to manually register plugins with :

GeneratedPluginRegistrant.registerWith(this);

as registration will happen automatically when FlutterEngine gets created.

I've made the necessary changes and can confirm your plugin works as expected in Android. My original Splash screen code no longer works but thats another matter and not related to your plugin.

Also - Just to confirm, I'm assuming this plugin DOES NOT USE UIWebView on the iOS side ?

Thanks

yes this plugin is using the lastest versions of Facebook sdk corekit uiwebview is not a problem

sallypeters commented 3 years ago

Thanks for the confirmation - Unfortunately, other older plugins I am using are not supporting


<meta-data
            android:name="flutterEmbedding"
            android:value="2" />

and require

GeneratedPluginRegistrant.registerWith(this);

For their Android context to be fully realised - They check that the main activity is a FlutterActivity and not an instance of FlutterEngine

Is it possible to generate a second backward-compatible version of your plugin that doesnt use the new 1.12 plugin API ?

MsXam commented 3 years ago

@sallypeters Unless the plugin developer creates a backward compatible version of this plugin to support pre 1.12 created Flutter apps then you will have to try and manually override the automatic registration of Plugins with the new FlutterEngine otherwise older plugins that do not conform to flutter embedding will invariable break.

Additionally - if all you require is Facebook authentication within your mobile app - then you can relatively easily create your own (non native dialogs) web flow authentication. You will need a registered callback URL or you can create an internal server within your Flutter app that listens on a set address/port for a 'success' when Facebook redirects to your specified URL.

There are many many existing Flutter apps out there that have been created pre 1.12 and thus cannot move away (for now) from io.flutter.app.FlutterActivity so it would make sense for Plugin developers to create backward compatible plugins - this would ensure a far greater scope and adoptability.

darwin-morocho commented 3 years ago

I'am closing this because is not an issue. The developer is using a flutter version less than 12.2

gianlucainnocente commented 3 years ago

Same problem here. We need a compatibility versione because 90% of projects cannot upgrade at the moment..

darwin-morocho commented 3 years ago

Same problem here. We need a compatibility versione because 90% of projects cannot upgrade at the moment..

I will launch a new version with support for flutter <12.2 on android in the next few days

krokyze commented 3 years ago

Same problem here. We need a compatibility versione because 90% of projects cannot upgrade at the moment..

I will launch a new version with support for flutter <12.2 on android in the next few days

Hey, any plan to release this soon?

darwin-morocho commented 3 years ago

Same problem here. We need a compatibility versione because 90% of projects cannot upgrade at the moment..

I will launch a new version with support for flutter <12.2 on android in the next few days

Hey, any plan to release this soon?

I'm working to add support for flutter projects that are using flutter sdk <12.2

gianlucainnocente commented 3 years ago

Same problem here. We need a compatibility versione because 90% of projects cannot upgrade at the moment..

I will launch a new version with support for flutter <12.2 on android in the next few days

Hey, any plan to release this soon?

I'm working to add support for flutter projects that are using flutter sdk <12.2

Any news about that? I really need it in production app 👍 Thank you