darwin-morocho / flutter-facebook-auth

A flutter plugin to add login with facebook in your flutter app
197 stars 144 forks source link

Unhandled Exception: MissingPluginException(No implementation found for method login on channel app.meedu/flutter_facebook_auth) #310

Open eav-solution opened 2 years ago

eav-solution commented 2 years ago

What version are you using?

5.0.6

What OS and version are you using to local deploy your application?

MacOS 13

What platforms are you seeing the problem on?

Android

pubspec.yaml

name: perdex
description: A new Flutter project.
publish_to: 'none' # Remove this line if you wish to publish to pub.dev

version: 1.0.0+1

environment:
  sdk: ">=2.7.0 <3.0.0"

dependencies:
  flutter:
    sdk: flutter

  cupertino_icons: ^0.1.3
  flutter_tts: ^2.1.0
  tflite_flutter: ^0.9.0
  hive: ^2.2.3
  hive_flutter: ^1.1.0
  gallery_saver: ^2.3.2
  image: ^3.0.2
  path_provider: ^2.0.1
  image_picker: ^0.8.5+3
  scidart: ^0.0.1-dev.9
  sqflite: ^2.0.2
  ml_linalg: ^13.10.0

  # Firebase
  firebase_core: ^2.3.0
  firebase_analytics: ^10.0.6
  cloud_firestore: ^4.1.0
  google_sign_in: ^5.4.2
  flutter_facebook_auth: ^4.4.1+1
  firebase_auth: ^4.1.3
  sign_in_with_apple: ^4.2.0
  crypto: ^3.0.2

  # Android
  camera: ^0.8.1+3
  tflite_flutter_helper:
    git:
      url: https://github.com/filofan1/tflite_flutter_helper.git
      ref: 783f15e5a87126159147d8ea30b98eea9207ac70

  # IOS
#  camera: ^0.9.4+5
#  tflite_flutter_helper: ^0.3.1

dev_dependencies:
  flutter_test:
    sdk: flutter

flutter:
  uses-material-design: true

  assets:
    - assets/

Describe the Bug

Cannot sign in with facebook.

Expected Behavior

Login facebook succesful.

To Reproduce

Future signInWithFacebook() async { // Trigger the sign-in flow final LoginResult loginResult = await FacebookAuth.instance.login();

// Create a credential from the access token final OAuthCredential facebookAuthCredential = FacebookAuthProvider.credential(loginResult.accessToken.token);

// Once signed in, return the UserCredential return FirebaseAuth.instance.signInWithCredential(facebookAuthCredential); }

Relevant log output

No response

flutter doctor -v

(tf) lkt@LKT-Macbook ~ % flutter doctor -v
[✓] Flutter (Channel stable, 3.3.0, on macOS 13.0.1 22A400 darwin-arm, locale
    en-VN)
    • Flutter version 3.3.0 on channel stable at
      /Users/lkt/Data/3.Flutter/SDK/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision ffccd96b62 (3 months ago), 2022-08-29 17:28:57 -0700
    • Engine revision 5e9e0e0aa8
    • Dart version 2.18.0
    • DevTools version 2.15.0

[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
    • Android SDK at /Users/lkt/Library/Android/sdk
    • Platform android-33, build-tools 31.0.0
    • Java binary at: /Applications/Android
      Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build
      11.0.13+0-b1751.21-8125866)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 14.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 14B47b
    • CocoaPods version 1.11.3

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2021.3)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build
      11.0.13+0-b1751.21-8125866)

[✓] VS Code (version 1.73.1)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.52.0

[✓] Connected device (3 available)
    • M2012K11AG (mobile) • 192.168.1.62:5555 • android-arm64  • Android 12 (API
      31)
    • macOS (desktop)     • macos             • darwin-arm64   • macOS 13.0.1
      22A400 darwin-arm
    • Chrome (web)        • chrome            • web-javascript • Google Chrome
      107.0.5304.110

[✓] HTTP Host Availability
    • All required HTTP hosts are available

• No issues found!
(tf) lkt@LKT-Macbook ~ %

Info.plist (iOS)

No response

Podfile (iOS)

No response

AndroidManifest.xml

No response

MainActivity.java

No response

MainActivity.kt

No response

index.html

No response

Info.plist (macOS)

I can run on ios without issue but android has this problem.
Please help me!
Thanks.
darwin-morocho commented 2 years ago

@eav-solution please add your AndroidManifest.xml

eav-solution commented 2 years ago

@eav-solution please add your AndroidManifest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.eav.perdex">

<queries>
    <provider android:authorities="com.facebook.katana.provider.PlatformProvider" />
</queries>

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<!-- io.flutter.app.FlutterApplication is an android.app.Application that
     calls FlutterMain.startInitialization(this); in its onCreate method.
     In most cases you can leave this as-is, but you if you want to provide
     additional functionality it is fine to subclass or reimplement
     FlutterApplication and put your custom class here. -->
<application
    android:name="${applicationName}"
    android:icon="@mipmap/ic_launcher"
    android:label="Perdex">
    <meta-data
        android:name="com.facebook.sdk.ApplicationId"
        android:value="528057332253406" />
    <meta-data
        android:name="com.facebook.sdk.ClientToken"
        android:value="792755a6c24c1b6e13f0f76331b5a954" />

    <activity
        android:name=".MainActivity"
        android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
        android:hardwareAccelerated="true"
        android:launchMode="singleTop"
        android:theme="@style/LaunchTheme"
        android:windowSoftInputMode="adjustResize">
        <!-- Specifies an Android theme to apply to this Activity as soon as
             the Android process has started. This theme is visible to the user
             while the Flutter UI initializes. After that, this theme continues
             to determine the Window background behind the Flutter UI. -->
        <meta-data
            android:name="io.flutter.embedding.android.NormalTheme"
            android:resource="@style/NormalTheme" />
        <!-- Displays an Android View that continues showing the launch screen
             Drawable until Flutter paints its first frame, then this splash
             screen fades out. A splash screen is useful to avoid any visual
             gap between the end of Android's launch screen and the painting of
             Flutter's first frame. -->
        <meta-data
            android:name="io.flutter.embedding.android.SplashScreenDrawable"
            android:resource="@drawable/launch_background" />
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <!-- Don't delete the meta-data below.
         This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
    <meta-data
        android:name="flutterEmbedding"
        android:value="2" />
</application>

I added, thanks you your support!

darwin-morocho commented 2 years ago

@eav-solution please add your AndroidManifest.xml

<queries>
    <provider android:authorities="com.facebook.katana.provider.PlatformProvider" />
</queries>

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<!-- io.flutter.app.FlutterApplication is an android.app.Application that
     calls FlutterMain.startInitialization(this); in its onCreate method.
     In most cases you can leave this as-is, but you if you want to provide
     additional functionality it is fine to subclass or reimplement
     FlutterApplication and put your custom class here. -->
<application
    android:name="${applicationName}"
    android:icon="@mipmap/ic_launcher"
    android:label="Perdex">
    <meta-data
        android:name="com.facebook.sdk.ApplicationId"
        android:value="528057332253406" />
    <meta-data
        android:name="com.facebook.sdk.ClientToken"
        android:value="792755a6c24c1b6e13f0f76331b5a954" />

    <activity
        android:name=".MainActivity"
        android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
        android:hardwareAccelerated="true"
        android:launchMode="singleTop"
        android:theme="@style/LaunchTheme"
        android:windowSoftInputMode="adjustResize">
        <!-- Specifies an Android theme to apply to this Activity as soon as
             the Android process has started. This theme is visible to the user
             while the Flutter UI initializes. After that, this theme continues
             to determine the Window background behind the Flutter UI. -->
        <meta-data
            android:name="io.flutter.embedding.android.NormalTheme"
            android:resource="@style/NormalTheme" />
        <!-- Displays an Android View that continues showing the launch screen
             Drawable until Flutter paints its first frame, then this splash
             screen fades out. A splash screen is useful to avoid any visual
             gap between the end of Android's launch screen and the painting of
             Flutter's first frame. -->
        <meta-data
            android:name="io.flutter.embedding.android.SplashScreenDrawable"
            android:resource="@drawable/launch_background" />
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <!-- Don't delete the meta-data below.
         This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
    <meta-data
        android:name="flutterEmbedding"
        android:value="2" />
</application>

I added, thanks you your support!

After install the plugin. Have you stopped the project and run it again?

Also don't forget the internet permission <uses-permission android:name="android.permission.INTERNET" />

eav-solution commented 2 years ago

@eav-solution please add your AndroidManifest.xml

<queries>
    <provider android:authorities="com.facebook.katana.provider.PlatformProvider" />
</queries>

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<!-- io.flutter.app.FlutterApplication is an android.app.Application that
     calls FlutterMain.startInitialization(this); in its onCreate method.
     In most cases you can leave this as-is, but you if you want to provide
     additional functionality it is fine to subclass or reimplement
     FlutterApplication and put your custom class here. -->
<application
    android:name="${applicationName}"
    android:icon="@mipmap/ic_launcher"
    android:label="Perdex">
    <meta-data
        android:name="com.facebook.sdk.ApplicationId"
        android:value="528057332253406" />
    <meta-data
        android:name="com.facebook.sdk.ClientToken"
        android:value="792755a6c24c1b6e13f0f76331b5a954" />

    <activity
        android:name=".MainActivity"
        android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
        android:hardwareAccelerated="true"
        android:launchMode="singleTop"
        android:theme="@style/LaunchTheme"
        android:windowSoftInputMode="adjustResize">
        <!-- Specifies an Android theme to apply to this Activity as soon as
             the Android process has started. This theme is visible to the user
             while the Flutter UI initializes. After that, this theme continues
             to determine the Window background behind the Flutter UI. -->
        <meta-data
            android:name="io.flutter.embedding.android.NormalTheme"
            android:resource="@style/NormalTheme" />
        <!-- Displays an Android View that continues showing the launch screen
             Drawable until Flutter paints its first frame, then this splash
             screen fades out. A splash screen is useful to avoid any visual
             gap between the end of Android's launch screen and the painting of
             Flutter's first frame. -->
        <meta-data
            android:name="io.flutter.embedding.android.SplashScreenDrawable"
            android:resource="@drawable/launch_background" />
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <!-- Don't delete the meta-data below.
         This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
    <meta-data
        android:name="flutterEmbedding"
        android:value="2" />
</application>

I added, thanks you your support!

After install the plugin. Have you stopped the project and run it again?

Also don't forget the internet permission <uses-permission android:name="android.permission.INTERNET" />

I cleaned project couple times and still got error with INTERNET permission added.

darwin-morocho commented 2 years ago

@eav-solution If you have a custom MainApplication class or MainActivity please add them.

eav-solution commented 2 years ago

I don't modify MainActivity.kt file. But MainActivity class doesn't have any thing in it class MainActivity{ }

eav-solution commented 2 years ago

@eav-solution If you have a custom MainApplication class or MainActivity please add them.

package com.eav.perdex

import io.flutter.embedding.android.FlutterActivity

class MainActivity: FlutterActivity() { }

darwin-morocho commented 2 years ago

@eav-solution https://github.com/darwin-morocho/flutter-facebook-auth/issues/290#issuecomment-1310732434

onurdev74 commented 1 year ago

Same

onurdev74 commented 1 year ago
Ekran Resmi 2023-02-05 13 27 30

Doesn't have android package ?

lukehutch commented 1 year ago

I have the same issue (in the Android emulator on Linux). The following steps don't solve the problem for me:

cd android
./gradlew clean build
cd ..
flutter clean
flutter run

My MainActivity is not modified. I have the INTERNET permission enabled.

I ran ./gradlew -d and checked the debug output. All the build steps for flutter_facebook_auth seem to be being performed as expected.

lukehutch commented 1 year ago

I also see in android/app/src/main/java/io/flutter/plugins/GeneratedPluginRegistrant.java:

      flutterEngine.getPlugins().add(new app.meedu.flutter_facebook_auth.FlutterFacebookAuthPlugin());

so the plugin is in fact loaded. I don't know why the method channel app.meedu.flutter_facebook_auth is not being registered.

lukehutch commented 1 year ago

I found the issue: when FlutterFacebookAuthPlugin calls new FacebookAuth(), the following exception is thrown, which causes the plugin registration to fail:

The SDK has not been initialized, make sure to call FacebookSdk.sdkInitialize() first.
lukehutch commented 1 year ago

FacebookSdk.sdkInitialize() is now deprecated, and initialization is done by means of a ContentProvider declared in the manifest:

https://stackoverflow.com/a/41884415/3950982

This means the com.facebook.android/facebook-core library should be initializing itself. However it is not, for some reason.

This ContentProvider, named FacebookInitProvider, is being correctly registered in the facebook-core library, so it should be run on startup:

https://github.com/facebook/facebook-android-sdk/blob/main/facebook-core/src/main/AndroidManifest.xml

I tried manually adding the facebook-core library as a dependency in my app, and that did not force the FacebookInitProvider to be run on startup.

I looked at build/app/intermediates/merged_manifest/debug/AndroidManifest.xml, and the provider is being correctly declared there:

        <provider
            android:name="com.facebook.internal.FacebookInitProvider"
            android:authorities="app.myapp.FacebookInitProvider"
            android:exported="false" />

Anyone have any ideas about what is going wrong?

lukehutch commented 1 year ago

OK, I solved it by setting a method breakpoint at class com.facebook.internal.FacebookInitProvider, method onCreate. It turns out the initialization was failing because the app id couldn't be found in my manifest file. I guess if a ContentProvider fails to initialize, nothing is written to the log :-/

The following two lines need to be in <manifest><application>..., not inside <manifest>.... (I didn't read the docs closely enough...)

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

This fixes the issue for me.

ftc300 commented 1 year ago

Actually, the error is: App Ids cannot be directly placed in the manifest.They must be prefixed by 'fb' or be placed in the string resource file. image I solved it by prefixing 'fb'. @eav-solution

eroldemirci commented 1 year ago

I had the same problem. I added the app id and client token directly to the manifest file. I added "fb" to the App ID (fb1234). My problem is solved

Plumillon commented 9 months ago

Problem solved by adding "fb" before the App ID 👍🏾. Could this be added to the doc?

darwin-morocho commented 9 months ago

Problem solved by adding "fb" before the App ID 👍🏾.

Could this be added to the doc?

In fact the documentación has an example with real data to configure the sdk on android

abdulkash commented 9 months ago

I'm getting the The SDK has not been initialized, make sure to call FacebookSdk.sdkInitialize() first. Here's my AndroidManifest.xml file

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    package="com.education.myschoollibrary">

    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"
        tools:node="remove" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"
        tools:node="remove" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"
        android:maxSdkVersion="32" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"
        android:maxSdkVersion="31" />

    <queries>
        <provider android:authorities="com.facebook.katana.provider.PlatformProvider" />
    </queries>

   <application
        android:label="My School Library"
        android:name="${applicationName}"
        android:icon="@mipmap/launcher_icon"
        tools:node="replace">

        <meta-data
                android:name="com.google.android.gms.ads.APPLICATION_ID"
                android:value="ca-app-pub-xxxxxxxx"/>
        <meta-data
                android:name="com.google.android.gms.version"
                android:value="@integer/google_play_services_version" />

        <activity
          android:name="com.google.android.gms.auth.api.signin.internal.SignInHubActivity"
          android:screenOrientation="portrait"
          android:windowSoftInputMode="stateAlwaysHidden|adjustPan" />

        <activity
            android:name=".MainActivity"
            android:exported="true"
            android:launchMode="singleTop"
            android:theme="@style/LaunchTheme"
            android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
            android:hardwareAccelerated="true"
            android:windowSoftInputMode="adjustResize">

            <meta-data
              android:name="io.flutter.embedding.android.NormalTheme"
              android:resource="@style/NormalTheme" />

            <meta-data
              android:name="io.flutter.embedding.android.SplashScreenDrawable"
              android:resource="@drawable/launch_background" />

            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>

        </activity>
       <!-- Facebook SDK // START-->

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

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

       <!-- Facebook SDK // END-->

        <!-- Don't delete the meta-data below.
             This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
        <meta-data
            android:name="flutterEmbedding"
            android:value="2" />
         <!-- Begin FlutterDownloader customization -->
        <!-- disable default Initializer -->
        <provider
            android:name="androidx.startup.InitializationProvider"
            android:authorities="${applicationId}.androidx-startup"
            android:exported="false"
            tools:node="merge">
            <meta-data
                android:name="androidx.work.WorkManagerInitializer"
                android:value="androidx.startup"
                tools:node="remove" />
        </provider>

        <!-- declare customized Initializer -->
        <provider
            android:name="vn.hunghd.flutterdownloader.FlutterDownloaderInitializer"
            android:authorities="${applicationId}.flutter-downloader-init"
            android:exported="false">
            <meta-data
                android:name="vn.hunghd.flutterdownloader.MAX_CONCURRENT_TASKS"
                android:value="1" />
        </provider>
        <!-- End FlutterDownloader customization -->
    </application>
</manifest>