darwin-morocho / flutter-facebook-auth

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

Getting Exception on androidx with latest package #330

Closed atulproject99 closed 1 year ago

atulproject99 commented 1 year ago

What version are you using?

flutter_facebook_auth: 5.0.7

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

macOS ventura 13.1

What platforms are you seeing the problem on?

Android

pubspec.yaml

name: golfers
version: 1.2.2+10
publish_to: none
description: A new Flutter project.
environment:
  sdk: ">=2.18.6 <3.0.0"

dependencies:
  back_button_interceptor: 6.0.2
  badges: 2.0.3
  cached_network_image: 3.2.2
  collection: 1.16.0
  crypto: 3.0.2
  cupertino_icons: 1.0.5
  dartz: 0.10.1
  dio: 4.0.6
  firebase_core: 2.7.0
  firebase_dynamic_links: 5.0.8
  firebase_messaging: 14.2.1
  flutter:
    sdk: flutter
  flutter_facebook_auth: ^5.0.7
  flutter_local_notifications: 12.0.4
  flutter_localizations:
    sdk: flutter
  flutter_pdfview: 1.2.5
  flutter_svg: 1.1.6
  get: 4.6.5
  get_cli: 0.2.30
  google_fonts: 3.0.1
  image_cropper: 3.0.1
  image_picker: 0.8.6
  intl: 0.17.0
  jiffy: 5.0.0
  local_auth: 2.1.2
  mime: 1.0.3
  mime_type: 1.0.0
  package_info_plus: 3.0.2
  path_provider: 2.0.11
  photo_view: 0.14.0
  pin_code_fields: 7.4.0
  qlevar_router: 1.7.1
  rive: 0.10.0
  rxdart: 0.27.6
  share_plus: 6.3.0
  shared_preferences: 2.0.15
  shimmer: 2.0.0
  showcaseview: 2.0.0+1
  simple_shadow: 0.3.0
  the_apple_sign_in: 1.1.1
  timezone: 0.9.0
  video_player: 2.4.8
  video_thumbnail: 0.5.3
  wakelock: 0.6.2

dev_dependencies:
  flutter_lints: 2.0.0
  flutter_test:
    sdk: flutter
flutter_localizations:
  sdk: flutter
flutter:
  assets:
    - assets/
    - assets/images/
    - assets/images/2x/
    - assets/images/3x/
    - assets/anim/
  uses-material-design: true

Describe the Bug

I getting this exception

W/class com.facebook.login.LoginManager( 2314): You're calling logging in Facebook with an activity supports androidx activity result APIs. Please follow our document to upgrade to new APIs to avoid overriding onActivityResult().

Expected Behavior

Not happening this . I want to simple login in app.

To Reproduce

import 'package:dartz/dartz.dart'; import 'package:flutter_facebook_auth/flutter_facebook_auth.dart';

import '../../../../../models/auth/social_auth_response_model.dart'; import '../../../../../common/api/golfers_error.dart'; import '../../../../../modules/register/controllers/register_controller.dart'; import 'meta_service.dart';

class MetaServicesImple extends MetaServices { final _fbAuth = FacebookAuth.instance; @override Future<Either<GolfersException, SocialAuthResponseModel>> signInWithFacebook() async { final LoginResult result = await _fbAuth.login( permissions: ['email'], );

switch (result.status) {
  case LoginStatus.success:
    final AccessToken accessToken = result.accessToken!;
    final userDetail = await _fbAuth.getUserData(
      fields: "name,email",
    );

    right(SocialAuthResponseModel(
      oAuthType: OAuthType.faceBookAuth.toInt,
      facebookAuthId: accessToken.token,
      email: userDetail['email'] ?? '',
    ));

    break;
  case LoginStatus.failed:
    return left(
        GolfersException(message: result.message.toString(), code: '-1'));

  case LoginStatus.cancelled:
    return left(
        GolfersException(message: 'Sign in aborted by user', code: '-2'));
  default:
    return left(GolfersException(
        message: 'Something went wrong. Please try again.', code: '-3'));
}

return left(GolfersException(
    message: 'Something went wrong. Please try again.', code: '-3'));

} }

Relevant log output

No response

flutter doctor -v

atulmaurya@Atuls-MacBook-Pro Golfers % flutter doctor -v
[✓] Flutter (Channel stable, 3.3.10, on macOS 13.1 22C65 darwin-arm, locale en-IN)
    • Flutter version 3.3.10 on channel stable at
      /Users/atulmaurya/Downloads/fluttersdk/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 135454af32 (2 months ago), 2022-12-15 07:36:55 -0800
    • Engine revision 3316dd8728
    • Dart version 2.18.6
    • DevTools version 2.15.0

[✓] Android toolchain - develop for Android devices (Android SDK version 32.1.0-rc1)
    • Android SDK at /Users/atulmaurya/Library/Android/sdk
    • Platform android-33, build-tools 32.1.0-rc1
    • Java binary at: /Applications/Android
      Studio.app/Contents/jre/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840)
    • 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.11.3

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

[✓] Android Studio (version 2021.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 11.0.12+0-b1504.28-7817840)

[✓] VS Code (version 1.66.1)
    • VS Code at /Users/atulmaurya/Downloads/Visual Studio Code.app/Contents
    • Flutter extension version 3.40.0

[✓] Connected device (4 available)
    • CPH2239 (mobile)            • YLDYSG9S8HON4SYT • android-arm64  • Android 11
      (API 30)
    • sdk gphone64 arm64 (mobile) • emulator-5554    • android-arm64  • Android 12
      (API 32) (emulator)
    • macOS (desktop)             • macos            • darwin-arm64   • macOS 13.1
      22C65 darwin-arm
    • Chrome (web)                • chrome           • web-javascript • Google
      Chrome 110.0.5481.100

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

• No issues found!

Info.plist (iOS)

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>CADisableMinimumFrameDurationOnPhone</key>
    <true/>
    <key>CFBundleDevelopmentRegion</key>
    <string>$(DEVELOPMENT_LANGUAGE)</string>
    <key>CFBundleDisplayName</key>
    <string>The Golfers App</string>
    <key>CFBundleExecutable</key>
    <string>$(EXECUTABLE_NAME)</string>
    <key>CFBundleIdentifier</key>
    <string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
    <key>CFBundleInfoDictionaryVersion</key>
    <string>6.0</string>
    <key>CFBundleName</key>
    <string>golfers</string>
    <key>CFBundlePackageType</key>
    <string>APPL</string>
    <key>CFBundleShortVersionString</key>
    <string>$(FLUTTER_BUILD_NAME)</string>
    <key>CFBundleSignature</key>
    <string>????</string>
    <key>CFBundleVersion</key>
    <string>$(FLUTTER_BUILD_NUMBER)</string>
    <key>LSRequiresIPhoneOS</key>
    <true/>
    <key>NSCameraUsageDescription</key>
    <string>Upload image from camera for profile picture</string>
    <key>NSFaceIDUsageDescription</key>
    <string>Biometric authentication for login</string>
    <key>NSPhotoLibraryUsageDescription</key>
    <string>Upload images for profile picture</string>
    <key>UIApplicationSupportsIndirectInputEvents</key>
    <true/>
    <key>UIBackgroundModes</key>
    <array>
        <string>remote-notification</string>
    </array>
    <key>CFBundleURLTypes</key>
<array>
  <dict>
    <key>CFBundleURLSchemes</key>
    <array>
      <string>fb{your-app-id}</string>
    </array>
  </dict>
</array>
<key>FacebookAppID</key>
<string>{your-app-id}</string>
<key>FacebookClientToken</key>
<string>CLIENT-TOKEN</string>
<key>FacebookDisplayName</key>
<string>{your-app-name}</string>
<key>LSApplicationQueriesSchemes</key>
<array>
  <string>fbapi</string>
  <string>fb-messenger-share-api</string>
</array>

    <key>UILaunchStoryboardName</key>
    <string>LaunchScreen</string>
    <key>UIMainStoryboardFile</key>
    <string>Main</string>
    <key>UISupportedInterfaceOrientations</key>
    <array>
        <string>UIInterfaceOrientationPortrait</string>
        <string>UIInterfaceOrientationLandscapeLeft</string>
        <string>UIInterfaceOrientationLandscapeRight</string>
    </array>
    <key>UISupportedInterfaceOrientations~ipad</key>
    <array>
        <string>UIInterfaceOrientationPortrait</string>
        <string>UIInterfaceOrientationPortraitUpsideDown</string>
        <string>UIInterfaceOrientationLandscapeLeft</string>
        <string>UIInterfaceOrientationLandscapeRight</string>
    </array>
    <key>UIViewControllerBasedStatusBarAppearance</key>
    <false/>
    <key>FirebaseAppDelegateProxyEnabled</key>
<false/>
</dict>
</plist>

Podfile (iOS)

# Uncomment this line to define a global platform for your project
platform :ios, '12.0'

# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
ENV['COCOAPODS_DISABLE_STATS'] = 'true'

project 'Runner', {
  'Debug' => :debug,
  'Profile' => :release,
  'Release' => :release,
}

def flutter_root
  generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'Generated.xcconfig'), __FILE__)
  unless File.exist?(generated_xcode_build_settings_path)
    raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure flutter pub get is executed first"
  end

  File.foreach(generated_xcode_build_settings_path) do |line|
    matches = line.match(/FLUTTER_ROOT\=(.*)/)
    return matches[1].strip if matches
  end
  raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Generated.xcconfig, then run flutter pub get"
end

require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root)

flutter_ios_podfile_setup

target 'Runner' do
  use_frameworks!
  use_modular_headers!

  flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))
end

post_install do |installer|
  installer.pods_project.targets.each do |target|
    flutter_additional_ios_build_settings(target)
  end
end

AndroidManifest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.golfers">
       <uses-permission android:name="android.permission.INTERNET" />
        <uses-permission android:name="android.permission.USE_BIOMETRIC"/>
        <queries>
          <provider android:authorities="com.facebook.katana.provider.PlatformProvider" />
      </queries>
   <application
        android:requestLegacyExternalStorage="true" 
        android:label="The Golfers App"
        android:name="${applicationName}"
        android:icon="@mipmap/ic_launcher"
        android:usesCleartextTraffic="true"
        >

        <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">
            <!-- 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>

            <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:host="https://golfers.demoserver23.com"
        android:scheme="https"/>
</intent-filter>
        </activity>

        <activity
    android:name="com.yalantis.ucrop.UCropActivity"
    android:screenOrientation="portrait"
    android:theme="@style/Theme.AppCompat.Light.NoActionBar"/>
        <!-- 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" />

<!-- For facebook login  -->
            <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"/>

<!-- <activity android:name="com.facebook.FacebookActivity" android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation" android:label="@string/app_name" android:exported="false" />
<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> -->
    </application>

</manifest>

MainActivity.java

No response

MainActivity.kt

package com.example.golfers

import io.flutter.embedding.android.FlutterFragmentActivity

class MainActivity: FlutterFragmentActivity() {
}

index.html

No response

Info.plist (macOS)

No response

darwin-morocho commented 1 year ago

@atulproject99 I have tried to reproduce the issue without success, even I have addapted the example https://github.com/darwin-morocho/flutter-facebook-auth/tree/master/facebook_auth/example to your android configuration.

Please run that example, replace with your facebook credentials and let me know if the issue persists.

Also if you can please add your android/app/build.gradle file

waqadArshad commented 4 months ago

@atulproject99 how did u solve this?