darwin-morocho / flutter-facebook-auth

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

[Android] - Facebook Login does not proceed if no Facebook App is installed #367

Closed justforworkandstuff closed 1 month ago

justforworkandstuff commented 5 months ago

What version are you using?

flutter_facebook_auth: ^5.0.11

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

macOS 12.5

What platforms are you seeing the problem on?

Android

pubspec.yaml

name: mag_app
description: Flutter app
#version: 1.0.0+1
publish_to: none

environment:
  sdk: ">=3.0.0 <4.0.0"

dependencies:
  bloc: ^8.0.3
  provider: ^6.0.3
  flutter:
    sdk: flutter
  flutter_bloc: ^8.0.1
  flutter_localizations:
    sdk: flutter
  intl: ^0.18.0

  #Social Share local package
  appinio_social_share: ^0.2.4
  social_share_plugin:
      path: ./social_share_plugin-master

  # Device Info
  device_info: ^2.0.0
  package_info: ^2.0.0
  store_redirect: ^2.0.1
  permission_handler: ^10.0.0
  flutter_jailbreak_detection: ^1.8.0
  connectivity_plus: ^3.0.2

  # Systems/Structure
  go_router: ^6.5.0
  go_router_builder: ^1.0.15
  focus_detector: ^2.0.1
  privacy_screen: ^0.0.6

  # Data
  dio: ^4.0.0
  shared_preferences: ^2.0.20
  path_provider: ^2.1.1
  email_validator: ^2.1.16
  file: ^6.1.4
  flutter_linkify: ^6.0.0
  linkify: ^5.0.0

  # Firebase
  firebase_core: ^2.15.1
  firebase_analytics: ^10.4.5
  firebase_messaging: ^14.6.7
  firebase_crashlytics: ^3.3.5
  firebase_remote_config: ^4.2.5
  firebase_performance: ^0.9.2
  firebase_core_platform_interface: 4.8.0
  firebase_app_installations: 0.2.3

  # Push Notification
  flutter_local_notifications: ^15.1.0

  # Ui/UX
  progress_state_button: ^1.0.4
  dots_indicator: ^2.1.0
  flutter_staggered_grid_view: ^0.6.2
  palette_generator: ^0.3.3+1
  pdfx: ^2.2.0
  internet_file: ^1.2.0
  slider_action: ^1.0.1
  video_player: ^2.4.7
  flutter_html: ^3.0.0-beta.2
  lottie: ^1.4.2
  flutter_inappwebview: ^5.4.3+7
  url_launcher: ^6.1.5
  photo_view: ^0.14.0
  qr_code_scanner: ^1.0.1
  audioplayers: ^4.1.0
  infinite_scroll_pagination: ^3.2.0
  flutter_svg: ^2.0.7
  flutter_chat_bubble: ^2.0.0
  google_maps_flutter: ^2.5.0
  map_launcher: ^2.4.0
  image_gallery_saver: ^1.7.1
  fluttertoast: ^8.0.9
  image_picker: ^0.8.6
  animations: ^2.0.7
  flutter_image: ^4.1.5
  sensors_plus: ^3.0.1
  dotted_line: ^3.2.2

  # Share
  share_whatsapp: ^1.0.2

  # Social Logins
  flutter_facebook_auth: ^5.0.11
  google_sign_in: ^5.4.1
  sign_in_with_apple: ^4.1.0
  in_app_review: ^2.0.4

flutter:
  uses-material-design: true
  generate: true
  assets:
    - assets/images-ms/
    - assets/images-en/
    - assets/images/
    - assets/json-ms/
    - assets/json-en/
    - assets/json/
    - assets/gif/
    - assets/audio/
    - assets/fonts/
  fonts:
    - family: Roboto
      fonts:
        - asset: assets/fonts/Roboto-Black.ttf
        - asset: assets/fonts/Roboto-BlackItalic.ttf
        - asset: assets/fonts/Roboto-Bold.ttf
        - asset: assets/fonts/Roboto-BoldItalic.ttf
        - asset: assets/fonts/Roboto-Italic.ttf
        - asset: assets/fonts/Roboto-Light.ttf
        - asset: assets/fonts/Roboto-LightItalic.ttf
        - asset: assets/fonts/Roboto-Medium.ttf
        - asset: assets/fonts/Roboto-MediumItalic.ttf
        - asset: assets/fonts/Roboto-Regular.ttf
        - asset: assets/fonts/Roboto-Thin.ttf
        - asset: assets/fonts/Roboto-ThinItalic.ttf
flutter_intl:
  enabled: true

Describe the Bug

Facebook Login does not work if the user's device does not have the Facebook app installed. This happens in Android.

Attached videos for reference.

https://github.com/darwin-morocho/flutter-facebook-auth/assets/52436338/667344d6-1635-4145-8260-14b96048115d

Expected Behavior

Facebook login should proceed normally through web if no Facebook app is installed.

To Reproduce

Issue should be able to reproduce through the following steps:

  1. Setup reproducible code
  2. Make sure user device is Android and does not have Facebook app installed
  3. Run Flutter app and reproduce an action click of the method proceedLoginFB()
  4. User should see a webView of Facebook Login Dialog
  5. Login user account where necessary
  6. Proceed as follows.
  7. User should not be able to proceed any further and gets stucked on the web page, until user closes the dialog.

Sample code to reproduce:

void proceedLoginFB() async {
    final results = await FacebookAuth.i.login();
    // [results] just returned a simple failed, with message '
    if (results.status == LoginStatus.success) {
        // call own backend api for login
    } else {
      WidgetUtil.showSnackBar(context, results.message.toString());
    }
  }

Relevant log output

W/com.facebook.internal.NativeProtocol( 5369): Apps that target Android API 30+ (Android 11+) cannot call Facebook native apps unless the package visibility needs are declared. Please follow https://developers.facebook.com/docs/android/troubleshooting/#faq_267321845055988 to make the declaration.
W/com.facebook.internal.NativeProtocol( 5369): Apps that target Android API 30+ (Android 11+) cannot call Facebook native apps unless the package visibility needs are declared. Please follow https://developers.facebook.com/docs/android/troubleshooting/#faq_267321845055988 to make the declaration.
E/BLASTBufferQueue( 5369): [ViewRootImpl[MainActivity]#12](f:0,a:1) Applying pending transactions on dtor 1
I/FA      ( 5369): Application backgrounded at: timestamp_millis: 1699951048103

flutter doctor -v

[!] Flutter (Channel stable, 3.10.2, on macOS 12.5 21G72 darwin-arm64, locale en-MY)
    • Flutter version 3.10.2 on channel stable at /Users/aslm043-vitti-android/fvm/versions/3.10.2
    ! Warning: `dart` on your path resolves to /opt/homebrew/Cellar/dart/2.19.5/libexec/bin/dart, which is not inside your current Flutter SDK checkout at /Users/aslm043-vitti-android/fvm/versions/3.10.2. Consider adding /Users/aslm043-vitti-android/fvm/versions/3.10.2/bin to the front of your path.
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 9cd3d0d9ff (6 months ago), 2023-05-23 20:57:28 -0700
    • Engine revision 90fa3ae28f
    • Dart version 3.0.2
    • DevTools version 2.23.1
    • If those were intentional, you can disregard the above warnings; however it is recommended to use "git" directly to perform update checks and upgrades.

[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0-rc2)
    • Android SDK at /Users/aslm043-vitti-android/Library/Android/sdk
    • Platform android-34, build-tools 34.0.0-rc2
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b802.4-9586694)
    • All Android licenses accepted.

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

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

[✓] Android Studio (version 2022.2)
    • 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 17.0.6+0-17.0.6b802.4-9586694)

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

[✓] Connected device (4 available)
    • MHA L29 (mobile)            • AHK7N16C16000965 • android-arm64  • Android 9 (API 28)
    • sdk gphone64 arm64 (mobile) • emulator-5554    • android-arm64  • Android 12 (API 32) (emulator)
    • macOS (desktop)             • macos            • darwin-arm64   • macOS 12.5 21G72 darwin-arm64
    • Chrome (web)                • chrome           • web-javascript • Google Chrome 119.0.6045.123

[✓] Network resources
    • All expected network resources are available.

! Doctor found issues in 1 category.

Info.plist (iOS)

No response

Podfile (iOS)

No response

AndroidManifest.xml

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

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
    <uses-permission android:name="android.permission.BLUETOOTH"
        android:maxSdkVersion="30" />

    <!-- For Android SDK version 31+ -->
    <uses-permission android:name="android.permission.BLUETOOTH_SCAN"
        tools:remove="android:usesPermissionFlags"
        tools:targetApi="s" />
    <uses-permission android:name="android.permission.BLUETOOTH_CONNECT"/>
    <uses-permission android:name="android.permission.CAMERA" />

    <uses-permission android:name="com.google.android.gms.permission.AD_ID" tools:node="remove"/>

    <queries>
        <provider android:authorities="com.facebook.katana.provider.PlatformProvider" /> <!-- allows app to access Facebook app features -->
        <provider android:authorities="com.facebook.orca.provider.PlatformProvider" /> <!-- allows sharing to Messenger app -->
        <package android:name="com.instagram.android" />
        <package android:name="com.facebook.katana" />
        <package android:name="org.telegram.messenger" />
        <package android:name="com.whatsapp" />
        <package android:name="com.twitter.android" />

        <intent>
            <action android:name="android.intent.action.SEND" />
            <data android:mimeType="image/*" />
        </intent>
    </queries>

   <application
       android:label="${appName}"
       android:icon="@mipmap/ic_launcher_mag"
       android:allowBackup="false"
       android:usesCleartextTraffic="false">

       <meta-data android:name="com.facebook.sdk.ClientToken" android:value="@string/facebook_client_token"/>
       <meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/facebook_app_id"/>
       <meta-data android:name="com.google.android.geo.API_KEY" android:value="${google_map_api_key}"/>
       <activity
           android:name="com.facebook.FacebookActivity"
           android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation"
           android:label="@string/app_name" />

       <activity
           android:name="com.facebook.CustomTabActivity"
           tools:replace="android:exported" android:exported="false">
           <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:exported="true"
            android:launchMode="singleTop"
            android:allowBackup="false"
            android:screenOrientation="portrait"
            android:theme="@style/Theme.SplashScreen"
            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"
              />            
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
            <!-- Deep linking -->
            <meta-data android:name="flutter_deeplinking_enabled" android:value="true" />
            <intent-filter android:autoVerify="true">
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
                <data android:scheme="${deeplink_scheme_name}"/>/>
            </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" />

       <meta-data
           android:name="com.google.firebase.messaging.default_notification_channel_id"
           android:value="@string/default_notification_channel_id"/>

       <provider
           android:name="androidx.core.content.FileProvider"
           android:authorities="${applicationId}.provider"
           android:exported="false"
           android:grantUriPermissions="true"
           tools:replace="android:authorities">
           <meta-data android:name="android.support.FILE_PROVIDER_PATHS"
               android:resource="@xml/provider_paths"
               tools:replace="android:resource"/>
       </provider>

       <provider android:authorities="@string/fb_authority_name"
           android:name="com.facebook.FacebookContentProvider"
           android:exported="true"
           android:readPermission="android.permission.READ_EXTERNAL_STORAGE"
           android:writePermission="android.permission.WRITE_EXTERNAL_STORAGE"
           android:grantUriPermissions="true"/>

    </application>
</manifest>

MainActivity.java

No response

MainActivity.kt

package com.app.mag

import io.flutter.embedding.android.FlutterActivity

class MainActivity: FlutterActivity() {
}

index.html

No response

Info.plist (macOS)

No response

darwin-morocho commented 5 months ago

@justforworkandstuff if you are using an emulator keep in mind that the chrome app must be updated to handle the chrome tab opened by the facebook sdk when the app is not installed.

In that cases try to use a real device for your tests

justforworkandstuff commented 5 months ago

hi @darwin-morocho, thanks a lot for the prompt reply on this!

For your information, I've did managed to test this issue out on both the emulator and real devices.

Seems like both cases are showing the same error.

Additional info with testing devices and chrome version: Xiaomi 11T Pro - v119.0.6045.135 Huawei Mate 9 - v119.0.6045.134 Pixel 2 API 32 (Emulator) - v91.0.4472.114 (Can't update the chrome version somehow)

Perhaps you could try to reproduce the issue? Thanks a lot.

GreatGatsby108 commented 4 months ago

Facing the same problem. Tried logging the LoginResult returned post login, and found this: FB LoginResult: status=LoginStatus.cancelled, message=User has cancelled login with facebook, token=null

@justforworkandstuff Were you able to find a solution/workaround for this?

justforworkandstuff commented 3 months ago

@GreatGatsby108 sorry for the late reply, but I haven't found any further idea on this.

I managed to test this on other apps that have Facebook login as well (but I am not sure the framework it was in) of the same platform (Android), I was able to login successfully. So I think that seems like an issue with this package.

darwin-morocho commented 3 months ago

I have tested the login Flow without any problem. Sorry but keep in mind that this plugin only wraps the native sdk with the dart code. If the login Flow does not work for you there are a lot of reasons like

If the problem persists open an issue in the oficial repo https://github.com/facebook/facebook-android-sdk

darwin-morocho commented 3 months ago

Also FacebookActivity and CustomTabActivity are deprecated please check

https://facebook.meedu.app/docs/6.x.x/android