darwin-morocho / flutter-facebook-auth

A flutter plugin to add login with facebook in your flutter app
191 stars 124 forks source link

Error registering plugin flutter_facebook_auth #348 #350

Closed BFELFISH closed 9 months ago

BFELFISH commented 11 months ago

What version are you using?

flutter_facebook_auth:3.5.7

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

MacOs 11.5

What platforms are you seeing the problem on?

Android

pubspec.yaml

name: flutter_facebook_auth
description: The easiest way to add facebook login to your flutter app, get user information, profile picture and more. Web support included.
version: 3.5.7
homepage: https://github.com/darwin-morocho/flutter-facebook-auth

environment:
  sdk: ">=2.12.0 <3.0.0"
  flutter: ">=2.0.0"

dependencies:
  flutter:
    sdk: flutter
  flutter_facebook_auth_platform_interface: ^2.7.1
  # flutter_facebook_auth_platform_interface:
  #   path: ../facebook_auth_platform_interface
  flutter_facebook_auth_web: ^2.6.0+2
  # flutter_facebook_auth_web:
  #   path: ../facebook_auth_web

dev_dependencies:
  flutter_test:
    sdk: flutter

flutter:
  plugin:
    platforms:
      android:
        package: app.meedu.flutter_facebook_auth
        pluginClass: FlutterFacebookAuthPlugin
      ios:
        pluginClass: FlutterFacebookAuthPlugin
      web:
        default_package: flutter_facebook_auth_web

Describe the Bug

I make my MainActivity which extends FlutterActivity as a child process,when MainActivity call super.configureFlutterEngine(flutterEngine), get the error. But if i make MainActivity as main process,it works fine. So how can i regist flutter_facebook_auth on child process.

Expected Behavior

I want to regist flutter_facebook_auth on child process.My main process is a native Activity names LaunchActivity,and i startActivity(new Intent(this,MainActivity.class)) immediately in LaunchActivity onCreate.

To Reproduce

1.create a Flutter project.make LuanchActivity as Main and Launch Activity. 2.create a MainActivity extends FlutterActivity 3.start MainActivity on LaunchActivity onCreate() 4.regist plugin on MainActivity configureFlutterEngine()

Relevant log output

Error registering plugin flutter_facebook_auth, app.meedu.flutter_facebook_auth.FlutterFacebookAuthPlugin The SDK has not been initialized, make sure to call FacebookSdk.sdkInitialize() first. at com.facebook.internal.Validate.sdkInitialized(Validate.kt:129) at com.facebook.FacebookSdk.getApplicationContext(FacebookSdk.kt:632) at app.meedu.flutter_facebook_auth.FacebookAuth.<init>(FacebookAuth.java:31) at app.meedu.flutter_facebook_auth.FlutterFacebookAuthPlugin.<init>(FlutterFacebookAuthPlugin.java:20) at io.flutter.plugins.GeneratedPluginRegistrant.registerWith(GeneratedPluginRegistrant.java:114) at java.lang.reflect.Method.invoke(Native Method) at io.flutter.embedding.engine.plugins.util.GeneratedPluginRegister.registerGeneratedPlugins(GeneratedPluginRegister.java:80) at io.flutter.embedding.android.FlutterActivity.configureFlutterEngine(FlutterActivity.java:1133) at xxx.xx.xxxxx.MainActivity.configureFlutterEngine(MainActivity.kt:136) at io.flutter.embedding.android.FlutterActivityAndFragmentDelegate.onAttach(FlutterActivityAndFragmentDelegate.java:206) at io.flutter.embedding.android.FlutterActivity.onCreate(FlutterActivity.java:495) at xxx.xx.xxxxx.MainActivity.onCreate(MainActivity.kt:126) at android.app.Activity.performCreate(Activity.java:8488) at android.app.Activity.performCreate(Activity.java:8461) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1343) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:4602) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4842) at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:113) at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:149) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:103) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2928) at android.os.Handler.dispatchMessage(Handler.java:117) at android.os.Looper.loopOnce(Looper.java:205) at android.os.Looper.loop(Looper.java:293) at android.app.ActivityThread.main(ActivityThread.java:9596) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:586) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1204)

flutter doctor -v

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.7.12, on macOS 11.5 20G71 darwin-arm64 (Rosetta), locale zh-Hans-CN)
[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.2)
[✗] Xcode - develop for iOS and macOS
    ✗ Xcode installation is incomplete; a full installation is necessary for iOS development.
      Download at: https://developer.apple.com/xcode/download/
      Or install Xcode via the App Store.
      Once installed, run:
        sudo xcode-select --switch /Applications/Xcode.app/Contents/Developer
        sudo xcodebuild -runFirstLaunch
    ✗ CocoaPods not installed.
        CocoaPods is used to retrieve the iOS and macOS platform side's plugin code that responds to your plugin usage on the Dart side.
        Without CocoaPods, plugins will not work on iOS or macOS.
        For more info, see https://flutter.dev/platform-plugins
      To install see https://guides.cocoapods.org/using/getting-started.html#installation for instructions.
[✗] Chrome - develop for the web (Cannot find Chrome executable at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome)
    ! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable.
[!] Android Studio
    ✗ Unable to find bundled Java version.
[✓] Android Studio (version 4.2)
[✓] Connected device (2 available)
[✓] HTTP Host Availability

Info.plist (iOS)

No response

Podfile (iOS)

No response

AndroidManifest.xml

<activity
            android:name=".LaunchActivity"
            android:exported="true"
            android:noHistory="true"
            android:process="xxx.xx.xxxx"
            android:theme="@style/LaunchTheme">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />

            </intent-filter>

        </activity>

        <activity
            android:name=".MainActivity"
            android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
            android:exported="true"
            android:hardwareAccelerated="true"
            android:launchMode="singleTask"
            android:process="xxx.xx.Mxxain"
            android:screenOrientation="portrait"
            android:theme="@style/LaunchTheme"
            android:windowSoftInputMode="adjustResize">
            <meta-data
                android:name="io.flutter.embedding.android.NormalTheme"
                android:resource="@style/NormalTheme" />

            <intent-filter>
                <action android:name="FLUTTER_NOTIFICATION_CLICK" />

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

            <intent-filter>
                <action android:name="xxx.xx.xxxxx.action" />

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

            <intent-filter>
                <action android:name="${applicationId}.xmpush.action" />

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

            <intent-filter>
                <action android:name="android.intent.action.VIEW" />

                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
                <!-- Accepts URIs that begin with YOUR_SCHEME://YOUR_HOST -->
                <data
                    android:host="xxx.xx"
                    android:scheme="xxxx" />
            </intent-filter>
        </activity>

MainActivity.java

No response

MainActivity.kt

package xxx.xx.xxxx

import android.content.Context
import android.content.Intent
import android.content.IntentFilter
import android.graphics.Bitmap
import android.graphics.Color
import android.os.Bundle
import android.os.Handler
import android.os.Looper
import android.os.Process
import android.view.PixelCopy
import android.view.View
import android.widget.FrameLayout
import android.widget.ImageView
import com.quwan.tt.core.log.Log
import io.flutter.embedding.android.FlutterActivity
import io.flutter.embedding.android.FlutterSurfaceView
import io.flutter.embedding.android.TransparencyMode
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.embedding.engine.FlutterEngineCache
import io.flutter.plugin.common.MethodChannel

class MainActivity : FlutterActivity() {
    companion object {
        private const val TAG = "MainActivity"
        private const val CHANNEL_NAME = "xxx.xx.xxxxx"
    }

    // this container will wrap the uiScreenshot + Flutter's UI view
    private var container: FrameLayout? = null

    // UI screenshot taken in onPause
    private var uiScreenshot: ImageView? = null

    // token to guard against async race conditions
    private var screenshotToken = 0

    // the surface that Flutter uses to draw the UI
    private var flutterSurfaceView: FlutterSurfaceView? = null
    private var receiver: KillReceiver? = null

    private var methodChannel: MethodChannel? = null

    // hook to remember the surface for taking screenshots
    override fun onFlutterSurfaceViewCreated(flutterSurfaceView: FlutterSurfaceView) {
        super.onFlutterSurfaceViewCreated(flutterSurfaceView)
        this.flutterSurfaceView = flutterSurfaceView

        receiver = object : KillReceiver() {
            override fun onReceive(context: Context, intent: Intent) {
                super.onReceive(context, intent)
                System.exit(0)
            }
        }
        val intentFilter = IntentFilter()
        intentFilter.addAction("xxx.xx.xxxxx.KillReceiver")
        registerReceiver(receiver, intentFilter)
    }

    override fun getTransparencyMode(): TransparencyMode = TransparencyMode.transparent

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        Log.i(TAG, "onCreate: $savedInstanceState")
    }

    override fun onNewIntent(intent: Intent) {
        super.onNewIntent(intent)
        Log.i(TAG, "onNewIntent: ${intent.action}, ${intent.data}")
    }

    override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
        super.configureFlutterEngine(flutterEngine)
        methodChannel = MethodChannel(flutterEngine.dartExecutor.binaryMessenger, CHANNEL_NAME)
    }

    override fun onTrimMemory(level: Int) {
        super.onTrimMemory(level)
        methodChannel?.invokeMethod("onTrimMemory", level)
    }

}

index.html

No response

Info.plist (macOS)

No response

darwin-morocho commented 11 months ago

@BFELFISH sorry but this is not an issue of this plugin. I think you must investigate about this and how to use the native facebook sdk on android for this purpose.

BFELFISH commented 11 months ago

@BFELFISH sorry but this is not an issue of this plugin. I think you must investigate about this and how to use the native facebook sdk on android for this purpose.

But if I add “ FacebookSdk.sdkInitialize(context); ” before “ loginManager = LoginManager.getInstance(); ” on FacebookAuth class 's constructor.It works. Is there any problem doing that ?