darwin-morocho / flutter-facebook-auth

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

Ask for add queries even when I added it #321

Closed LeandroMoura3 closed 1 year ago

LeandroMoura3 commented 1 year ago

What version are you using?

5.0.4

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

win10

What platforms are you seeing the problem on?

Android

pubspec.yaml

name: MCB
description: Aplicativo do Núcleo Comunitário do Brasil

publish_to: "none"

version: 0.5.8+16

environment:
  sdk: ">=2.17.0 <3.0.0"

dependencies:
  http: ^0.13.4
  flutter_secure_storage: ^7.0.1
  path_provider: ^2.0.10
  youtube_player_iframe: ^3.1.0
  photo_view: ^0.14.0
  mask_text_input_formatter: ^2.3.0
  flutter_svg: ^1.1.0
  url_launcher: ^6.1.3
  package_info_plus: ^1.4.2
  wechat_assets_picker: ^8.1.1
  google_sign_in: ^5.4.2
  firebase_core: ^2.4.1
  flutter_facebook_auth: ^5.0.7
  flutter:
    sdk: flutter
  flutter_localizations:
    sdk: flutter

dev_dependencies:
  flutter_test:
    sdk: flutter

  dart_code_metrics: ^4.14.0
  flutter_lints: ^1.0.0

flutter:
  uses-material-design: true
  assets:
    - assets/instagram.svg
    - assets/youtube.svg

Describe the Bug

Even when add the queries to allow Android 30+ communication, show in console the message below and don't work authentication:

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.

Expected Behavior

The authentication works.

To Reproduce

I follow all steps of tutorial, includes the hash key and add MainActivity, but still not working.

Relevant log output

No response

flutter doctor -v

[√] Flutter (Channel stable, 3.3.10, on Microsoft Windows [versÆo 10.0.19044.2364],
    locale pt-BR)
    • Flutter version 3.3.10 on channel stable at C:\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 135454af32 (3 weeks ago), 2022-12-15 07:36:55 -0800        
    • Engine revision 3316dd8728
    • Dart version 2.18.6
    • DevTools version 2.15.0

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)

No response

darwin-morocho commented 1 year ago

@LeandroMoura3 please add your AndroidManifest

LeandroMoura3 commented 1 year ago

Sorry for that,

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="mcb.meubairro">
   <application
        android:label="MCB"
        android:name="${applicationName}"
        android:requestLegacyExternalStorage="true"
        android:icon="@mipmap/ic_launcher">
        <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=".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>
        </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>
    <queries>
        <provider android:authorities="com.facebook.katana.provider.PlatformProvider" /> <!-- allows app to access Facebook app features -->
    </queries>
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission
        android:name="android.permission.WRITE_EXTERNAL_STORAGE"
        android:maxSdkVersion="29"/>
</manifest>

There is.

LeandroMoura3 commented 1 year ago

Here is the package name and className. I think that is correct. I review it some times.

image

LeandroMoura3 commented 1 year ago

There is the console message that is show to me when I call the facebook_api call:

app_time_stats: avg=67.54ms min=7.07ms max=867.61ms count=17 W/com.facebook.internal.NativeProtocol( 4442): 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.

Exist a chance that this message show because my keyshash is wrong?

darwin-morocho commented 1 year ago

@LeandroMoura3 this tags must be at the beginning of the Manifest tag

    <queries>
        <provider android:authorities="com.facebook.katana.provider.PlatformProvider" /> <!-- allows app to access Facebook app features -->
    </queries>
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission
        android:name="android.permission.WRITE_EXTERNAL_STORAGE"
        android:maxSdkVersion="29"/>

check the example

<manifest package="com.example.app">
    <queries>
        <provider android:authorities="com.facebook.katana.provider.PlatformProvider" />
    </queries>
    ...
</manifest>

Also a package name must have at least 3 parts [domain extension].[domain name].[your app name] without blank spaces (instead of you must use underscore) here an valid example com.example.app

IMPORTANT Since the native facebook sdk 15.0.0 the minSdkVersion required is 21. You must go to android/app/build.gradle and define minSdkVersion to 21


    defaultConfig {
        ...
        minSdkVersion 21
        targetSdkVersion 33
        ...
    }
LeandroMoura3 commented 1 year ago

Here is my new manifest version:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="mcb.meubairro">
    <queries>
        <provider android:authorities="com.facebook.katana.provider.PlatformProvider" /> <!-- allows app to access Facebook app features -->
    </queries>
   <application
        android:label="MCB"
        android:name="${applicationName}"
        android:requestLegacyExternalStorage="true"
        android:icon="@mipmap/ic_launcher">
        <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=".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>
        </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>
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission
        android:name="android.permission.WRITE_EXTERNAL_STORAGE"
        android:maxSdkVersion="29"/>
</manifest>

I do flutter clean, flutter run and still experiment the problem related above.

I try to change my package name to com.mcb.meubairro.MainActivity, because in my folder is this structure: app/src/main/kotlin/mcb/MainActivity.kt

My MainActivity is a flutter default activity:

package mcb.meubairro

import io.flutter.embedding.android.FlutterActivity

class MainActivity: FlutterActivity() {
}
darwin-morocho commented 1 year ago

@LeandroMoura3 it seems that this issue must be opened in the official facebook repo https://github.com/facebook/facebook-android-sdk due to this plugin only connect with the java code of this sdk but all the configuration is handled by the native sdk

LeandroMoura3 commented 1 year ago

I think that I don't have the experience in native andriod to open this issue. So, for now, I will wait and try another authentication method.

Thenk you for you support.

darwin-morocho commented 1 year ago

I think that I don't have the experience in native andriod to open this issue. So, for now, I will wait and try another authentication method.

Thenk you for you support.

You don't need experiencie with native code to open the issue Just add the all steps that you followed inside the android folder to configure this plugin

LeandroMoura3 commented 1 year ago

Last day II have install the google authentication. I have success with that. One of the problems that I have is put the hashkey wrog.

Can you try put your hashkey wrong to test if the message is the same as this problem? If yes, so my problem is the hashkey. If not, I open a issue on github facebook.

I don't understand your explanation about facebook SDK configurations.

darwin-morocho commented 1 year ago

@LeandroMoura3 when you put an invalid keyhash you have a different error message. Instead of

  <queries>
        <provider android:authorities="com.facebook.katana.provider.PlatformProvider" /> <!-- allows app to access Facebook app features -->
    </queries>

try with

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

If that did not work try using flutter_facebook_auth: 4.4.1+1

If you think that the key hash could be the problem (is a common problem on windows) you can follow the next documentation to generate your key hash using native code https://developers.facebook.com/docs/android/getting-started#create_hash