darwin-morocho / flutter-facebook-auth

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

[Flutter] Put <meta-data> in <application> makes the apk crash or a black screen. #323

Closed JackHuang111 closed 9 months ago

JackHuang111 commented 1 year ago

What version are you using?

flutter_facebook_auth ^5.0.6

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

windows 11

What platforms are you seeing the problem on?

Android

pubspec.yaml

dependencies:
  youtube_player_flutter: 8.0.0
  pod_player: ^0.0.5
  firebase_analytics: 9.3.3
  firebase_core: 1.21.1
  firebase_crashlytics: 2.8.9
  firebase_dynamic_links: 4.3.11
  flutter:
    sdk: flutter
  flutter_localizations:
    sdk: flutter
  shared_preferences: ^2.0.6
  sqflite: ^2.0.0+3
  flutter_svg:
  url_launcher:
  fluttertoast: ^8.0.8
  flutter_bloc: ^7.2.0
  freezed_annotation: 1.1.0
  flutter_riverpod: ^1.0.3
  get_it: ^7.2.0
  intl: ^0.17.0
  dropdown_button2: 1.4.0
  buttons_tabbar: ^1.3.1
  package_info_plus: ^1.4.2
  flutter_facebook_sdk: ^1.0.0
  percent_indicator: 4.0.0
  flutter_staggered_grid_view: 0.4.0
  share_plus: ^4.0.10
  badges:
  firebase_messaging: ^11.4.1
  flutter_local_notifications: 9.3.1
  google_sign_in: ^5.4.3
  sign_in_with_apple: ^4.3.0
  flutter_facebook_auth: ^5.0.6
  firebase_auth: ^3.4.2

Describe the Bug

I just follow the document to seting up the file. https://facebook.meedu.app/docs/5.x.x/android After that, I run the flutter app and goes crash.

Expected Behavior

Launch app and login with facebook successfully.

To Reproduce

according to this document Android configuration https://facebook.meedu.app/docs/5.x.x/android

<application android:label="&#064;string/app_name" ...>
    ...
    <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"/>
    ...
</application>

Relevant log output

No response

flutter doctor -v

[√] Flutter (Channel stable, 2.10.5, on Microsoft Windows [Version 10.0.19044.2486], locale zh-TW)
    • Flutter version 2.10.5 at C:\flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 5464c5bac7 (9 months ago), 2022-04-18 09:55:37 -0700
    • Engine revision 57d3bac3dd
    • Dart version 2.16.2
    • DevTools version 2.9.2

[√] Android toolchain - develop for Android devices (Android SDK version 33.0.1)
    • Android SDK at C:\Users\user\AppData\Local\Android\sdk
    • Platform android-33, build-tools 33.0.1
    • Java binary at: D:\AndroidStudio\jre\bin\java
    • Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)
    • All Android licenses accepted.

[√] Chrome - develop for the web
    • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe

[X] Visual Studio - develop for Windows
    X Visual Studio not installed; this is necessary for Windows development.
      Download at https://visualstudio.microsoft.com/downloads/.
      Please install the "Desktop development with C++" workload, including all of its default components

[√] Android Studio (version 2021.3)
    • Android Studio at D:\AndroidStudio
    • 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.13+0-b1751.21-8125866)

[√] IntelliJ IDEA Ultimate Edition (version 2020.2)
    • IntelliJ at D:\IntelliJ IDEA 2020.2.1
    • Flutter plugin installed
    • Dart plugin version 202.8531

[√] Connected device (4 available)
    • SM A920F (mobile) • 2cd04645851d7ece • android-arm64  • Android 10 (API 29)
    • Windows (desktop) • windows          • windows-x64    • Microsoft Windows [Version 10.0.19044.2486]
    • Chrome (web)      • chrome           • web-javascript • Google Chrome 106.0.5249.119
    • Edge (web)        • edge             • web-javascript • Microsoft Edge 109.0.1518.55

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

Info.plist (iOS)

No response

Podfile (iOS)

No response

AndroidManifest.xml

<application
            android:label="*****"
            android:name="${applicationName}"
            android:icon="@mipmap/ic_launcher">
        <meta-data
                android:name="flutterEmbedding"
                android:value="2"/>
        <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"/>
        <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>

MainActivity.java

No response

MainActivity.kt

package *****

import io.flutter.embedding.android.FlutterActivity

class MainActivity: FlutterActivity() {
}

index.html

No response

Info.plist (macOS)

No response

darwin-morocho commented 1 year ago

@JackHuang111 sorry but the problem is not the meta data tags. They are in the right place, you can check the official facebook documentation https://developers.facebook.com/docs/facebook-login/android

I'm almost sure the error is due to a bad configuration in your AndroidManifest. If you don't put the complete code of that file I cannot help you.

Keep in mind that you must be created the string.xml file in/android/app/src/main/res/values/strings.xml with your facebook app id and your client token

JackHuang111 commented 1 year ago

@darwin-morocho here is my full AndroidManifest. And the string.xml is also setting done.

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.jooca.kitchenhand.launch.kitchenhand">
    <uses-permission android:name="android.permission.INTERNET"/>
    <queries>
        <provider android:authorities="com.facebook.katana.provider.PlatformProvider"/>
    </queries>

    <application
            android:label="kitchenhand"
            android:name="${applicationName}"
            android:icon="@mipmap/ic_launcher">
        <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="kitchenhand.page.link"
                        android:scheme="https"/>
            </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.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"/>
        <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>
darwin-morocho commented 1 year ago

@JackHuang111 since flutter_facebook_auth: 4.x you don't need

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

Try to remove that tags.

Also any permission tag must be after the queries tag.

check this example https://github.com/darwin-morocho/flutter-facebook-auth/blob/master/examples/with_provider/android/app/src/main/AndroidManifest.xml

Also please run your app since android studio and copy the error logs from your logcat and put them here

JackHuang111 commented 1 year ago

I removed the activity part and this is the log after that. It shows a blank screen, and got another problem. I have already upgrade flutter_local_notifications to 12.0.4 but still not work. I wonder if it is needed to upgrade flutter_local_notifications to 13.0.0 .....

√  Built build\app\outputs\flutter-apk\app-debug.apk.
Debug service listening on ws://127.0.0.1:4215/1WHvkvUDxa4=/ws
Syncing files to device SM A920F...
I/flutter ( 9393): Firebase.initializeApp() completed
I/flutter ( 9393): **** eSoMk8cmSImqQch6Bqm6AD:APA91bFrZsj1AdN-c8Ag3Z02NfRPkn6_lmwI3QgR0i6Kv1JQEduTnp-OYB17-eDtXtFjqmCS_VCZBaU9vokH2O-HudOjU10BUEHtzfvRM8cbYLECjc7IlUGXjozQwv0wI1AE1XF4rjMT
E/flutter ( 9393): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: MissingPluginException(No implementation found for method createNotificationChannel on channel dexterous.com/flutter/local_notifications)
E/flutter ( 9393): #0      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:175:7)
E/flutter ( 9393): <asynchronous suspension>
E/flutter ( 9393): #1      main (package:easy_cook/main.dart:60:5)
E/flutter ( 9393): <asynchronous suspension>
E/flutter ( 9393): 
I/chenhand.launc( 9393): Compiler allocated 4266KB to compile void android.view.ViewRootImpl.performTraversals()
darwin-morocho commented 1 year ago

@JackHuang111 sorry but I don't have the enough info about what is the problem. So I am not able to help you