darwin-morocho / flutter-facebook-auth

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

Using the packages `image_picker` and `flutter_facebook_auth` returns MissingPluginException #51

Closed aeviou closed 3 years ago

aeviou commented 3 years ago

Describe the bug Using the package image_picker and flutter_facebook_auth together creates the following error:

Unhandled Exception: MissingPluginException(No implementation found for method pickImage on channel plugins.flutter.io/image_picker)

Removing flutter_facebook_auth as a dependency fixes the bug.

Environment flutter doctor -v

[√] Flutter (Channel beta, 1.26.0-17.3.pre, on Microsoft Windows [Version 10.0.18363.1379], locale en-US)
    • Flutter version 1.26.0-17.3.pre at C:\flutter
    • Framework revision 4b50ca7f7f (9 days ago), 2021-02-04 19:44:27 -0800
    • Engine revision 2c527d6c7e
    • Dart version 2.12.0 (build 2.12.0-259.8.beta)

[√] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
    • Android SDK at C:\Users\Admin\AppData\Local\Android\Sdk
    • Platform android-30, build-tools 30.0.3
    • ANDROID_HOME = C:\Users\Admin\AppData\Local\Android\Sdk
    • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java      
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)
    • All Android licenses accepted.

[√] Android Studio (version 4.1.0)
    • Android Studio at C:\Program Files\Android\Android Studio
    • 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 1.8.0_242-release-1644-b01)

[√] VS Code (version 1.53.0)
    • VS Code at C:\Users\Admin\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.19.0

[√] Connected device (1 available)
    • ONEPLUS A6003 (mobile) • bdc3a9a1 • android-arm64 • Android 10 (API 29)

• No issues found!

pubspec.yaml

environment:
  sdk: ">=2.7.0 <3.0.0"

dependencies:
  flutter:
    sdk: flutter
  firebase_core: "0.7.0"
  firebase_auth: "^0.20.0+1"
  firebase_analytics: ^7.0.1
  firebase_storage: ^7.0.0
  cloud_firestore: "^0.16.0"
  provider: ^4.3.3
  intl: ^0.16.1

  image_picker: ^0.6.7
  flutter_facebook_auth: ^2.0.2
  flutter_screenutil: ^4.0.3+1  

AndroidManifest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="transplant.app">
   <uses-permission android:name="android.permission.CAMERA" />
   <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
   <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
   <uses-permission android:name="android.permission.FLASHLIGHT" />

   <application
        android:label="transplant"
        android:icon="@mipmap/ic_launcher"
        android:requestLegacyExternalStorage="true">
        <activity
            android:name=".MainActivity"
            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">
            <!-- 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>
</manifest>

To Reproduce: List flutter_facebook_auth: ^2.0.2 and image_picker: ^0.6.7 as dependencies. Use image_picker .getImage() function.

Execute the following code:

final picker = ImagePicker();
await picker.getImage(source: ImageSource.camera);

Expected behavior: Expected no dependency clash and the function to work as expected.

Screenshots

E/flutter ( 8747): [ERROR:topaz/lib/tonic/logging/dart_error.cc(16)] Unhandled exception:
E/flutter ( 8747): MissingPluginException(No implementation found for method pickImage on channel plugins.flutter.io/image_picker)
E/flutter ( 8747): #0      MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:278:7)
E/flutter ( 8747): <asynchronous suspension>
darwin-morocho commented 3 years ago

Hi @aeviou before run the app you need configure this plugin on Android. if you don't need it yet comment it from your pubspec.yaml

https://github.com/darwin-morocho/flutter-facebook-auth/tree/master/facebook_auth#installation

aeviou commented 3 years ago

Thank you I must have missed those steps! However, I went through all of the steps, ran flutter clean and flutter run and the problem persists.

darwin-morocho commented 3 years ago

Thank you I must have missed those steps! However, I went through all of the steps, ran flutter clean and flutter run and the problem persists.

Please add your configuration

Your AndroidManifest.xml, your pubspect.yaml, your MainActivity and your flutter doctor - v logs.

Here you have a project demo with a correct Android and iOS configuration https://github.com/meedu-app/flutter-facebook-login-example/tree/firebase_auth

In fact I have never had this problem I think this is a flutter issue because only happens on certain Android configurations.

Maybe this can help you https://github.com/flutter/flutter/issues/66833#issuecomment-735284283

aeviou commented 3 years ago

Adding image_picker to the clean build you provided works. I'm going to back pedal and add the remaining libraries and configurations one by one until I hopefully arrive at the issue. I'll post back here if I discover anything and otherwise close the thread. Thanks for the help thus far!

darwin-morocho commented 3 years ago

Adding image_picker to the clean build you provided works. I'm going to back pedal and add the remaining libraries and configurations one by one until I hopefully arrive at the issue. I'll post back here if I discover anything and otherwise close the thread. Thanks for the help thus far!

Maybe you need to check your Android configuration https://github.com/FirebaseExtended/flutterfire/issues/3212#issuecomment-676112777

aeviou commented 3 years ago

I remade a project from scratch and ported over the code from the example project. The code ran without image_picker, but upon adding the dependency image_picker: ^0.6.7+22 and running the following code, I was met with the same error.

  Future getImage() async {
    final pickedFile = await picker.getImage(source: ImageSource.gallery);

    setState(() {
      if (pickedFile != null) {
        _image = File(pickedFile.path);
      } else {
        print('No image selected.');
      }
    });
  }

Here's a breakdown of what's different between the configuration of the example project and the scratch project I made.

Identical Files:

AndroidManifest.XML (All three)
google-services.json
app/src/main/res/values/strings.xml
app/src/main/res/values/styles.xml

Differing Files:

Gradle Version (6.7.2) from Gradle (5.6.2)

Kotlin vs Java - The example project uses Java for MainActivity whereas my new project defaults to using Kotlin.

android\build.gradle has the following additions:

buildscript {
    ext.kotlin_version = '1.3.50'

    dependencies {
        classpath 'com.android.tools.build:gradle:4.1.0' (Previously 3.5.0)
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }

android\app\build.gradle has the following additions:

apply plugin: 'kotlin-android'
android {
    compileSdkVersion 30 (Previously 29)

    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
    }
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}

I suspect it has something to do with the MainAcitivty file or the Gradle build, but not sure after that.


AndroidManifest.XML

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="app.meedu.facebook_auth_example">

    <uses-permission android:name="android.permission.INTERNET" />
    <application
        android:name="io.flutter.app.FlutterApplication"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name">

        <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">
            <intent-filter><action android:name="android.intent.action.VIEW" />

                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />

                <data android:scheme="@string/fb_login_protocol_scheme" />
            </intent-filter>
        </activity>

        <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>
</manifest>

pubspec.yaml

name: facebook_auth_example
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: ^1.0.0
  flutter_facebook_auth: ^2.0.2
  firebase_core: ^0.5.2
  firebase_auth: ^0.18.3
  google_sign_in: ^4.5.9
  flutter_signin_button: ^1.1.0
  sign_in_with_apple: ^2.5.4
  path_provider: ^1.6.24
  image_picker: ^0.6.7+22

dev_dependencies:
  flutter_test:
    sdk: flutter

flutter:
  uses-material-design: true

flutter doctor -v

[√] Flutter (Channel beta, 1.26.0-17.6.pre, on Microsoft Windows [Version 10.0.18363.1379], locale en-US)
    • Flutter version 1.26.0-17.6.pre at C:\flutter
    • Framework revision a29104a69b (9 hours ago), 2021-02-16 09:26:56 -0800
    • Engine revision 21fa8bb99e
    • Dart version 2.12.0 (build 2.12.0-259.12.beta)

[√] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
    • Android SDK at C:\Users\Admin\AppData\Local\Android\Sdk
    • Platform android-30, build-tools 30.0.3
    • ANDROID_HOME = C:\Users\Admin\AppData\Local\Android\Sdk
    • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)
    • All Android licenses accepted.

[√] Android Studio (version 4.1.0)
    • Android Studio at C:\Program Files\Android\Android Studio
    • 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 1.8.0_242-release-1644-b01)

[√] VS Code (version 1.53.2)
    • VS Code at C:\Users\Admin\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.19.0

[√] Connected device (1 available)
    • sdk gphone x86 arm (mobile) • emulator-5554 • android-x86 • Android 11 (API 30) (emulator)

MainActivity.kt

package app.meedu.facebook_auth_example

import io.flutter.embedding.android.FlutterActivity

class MainActivity: FlutterActivity() {
}
darwin-morocho commented 3 years ago

I will try adding image_picker to reproduce the issue

darwin-morocho commented 3 years ago

@aeviou I've added image_picker to the example without any problem.

Also I've created a new example using kotlin and swift and I had the Unhandled Exception: MissingPluginException(No implementation found for method pickImage on channel plugins.flutter.io/image_picker) error if I call the next code before configure this plugin on Android. Next I've configured the plugin on Android and everything works. Here you have the new example https://github.com/meedu-app/flutter-facebook-login-example/tree/kotlin

Can you provide me the access to your code to check your error?

aeviou commented 3 years ago

Thanks for following up on this. I've been double checking along the steps to minimize the deviance in the code from initialization to where the error comes up and this is what I've come up with.

https://github.com/aeviou/fb_auth_image_picker

darwin-morocho commented 3 years ago

Thanks for following up on this. I've been double checking along the steps to minimize the deviance in the code from initialization to where the error comes up and this is what I've come up with.

https://github.com/aeviou/fb_auth_image_picker

After check your code you don't have the Android configuration in your AndroidManifest.xml I will close this issue because you've omited the Android configuration