firebase / flutterfire

🔥 A collection of Firebase plugins for Flutter apps.
https://firebase.google.com/docs/flutter/setup
BSD 3-Clause "New" or "Revised" License
8.63k stars 3.95k forks source link

🐛 [firebase_core] Android RELEASE Build Stuck On Splash Screen/CRASH #4410

Closed danielgchap closed 3 years ago

danielgchap commented 3 years ago

Bug report

Describe the bug

Installing a release Android build with Flutter from Visual Studio Code results in hanging on splash screen and error output. This ONLY occurs on release builds.

Steps to reproduce

Steps to reproduce the behavior:

  1. Install app on Android device (flutter run --release)
  2. Hangs on splash screen

Expected behavior

App runs to login screen.


Additional context

Add any other context about the problem here.

Main file:

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp();
  await SharedPreferences.getInstance();
  Admob.initialize();
  await Admob.requestTrackingAuthorization();

  DynamicLinkService.handleDynamicLinks();
  SystemChrome.setPreferredOrientations(
      [DeviceOrientation.portraitDown, DeviceOrientation.portraitUp]).then(
    (_) {
      runApp(
        StringConstants(
          child: AuthProvider(auth: Auth(), child: MyApp()),
        ),
      );
    },
  );
}

Error Output:

E/flutter (27229): [ERROR:flutter/lib/ui/ui_dart_state.cc(184)] Unhandled Exception: MissingPluginException(No implementation found for method Firebase#initializeCore on channel plugins.flutter.io/firebase_core)
E/flutter (27229): #0      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:160)
E/flutter (27229): <asynchronous suspension>
E/flutter (27229): #1      MethodChannel.invokeListMethod (package:flutter/src/services/platform_channel.dart:348)
E/flutter (27229): <asynchronous suspension>
E/flutter (27229): #2      MethodChannelFirebase._initializeCore (package:firebase_core_platform_interface/src/method_channel/method_channel_firebase.dart:30)
E/flutter (27229): <asynchronous suspension>
E/flutter (27229): #3      MethodChannelFirebase.initializeApp (package:firebase_core_platform_interface/src/method_channel/method_channel_firebase.dart:75)
E/flutter (27229): <asynchronous suspension>
E/flutter (27229): #4      Firebase.initializeApp (package:firebase_core/src/firebase.dart:43)
E/flutter (27229): <asynchronous suspension>
E/flutter (27229): #5      main (package:instapray/main.dart:20)
E/flutter (27229): <asynchronous suspension>
E/flutter (27229): 

Flutter doctor

Run flutter doctor and paste the output below:

Click To Expand ``` [✓] Flutter (Channel master, 1.25.0-9.0.pre.88, on Mac OS X 10.15.7 19H15 darwin-x64, locale en-US) • Flutter version 1.25.0-9.0.pre.88 at /Users/danielchapman/Dev/flutter • Framework revision e24e763872 (4 hours ago), 2020-12-16 07:33:03 -0500 • Engine revision e9f2f0eaea • Dart version 2.12.0 (build 2.12.0-157.0.dev) [✓] Android toolchain - develop for Android devices (Android SDK version 30.0.2) • Android SDK at /Users/danielchapman/Library/Android/sdk • Platform android-30, build-tools 30.0.2 • Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6915495) • All Android licenses accepted. [✓] Xcode - develop for iOS and macOS (Xcode 12.2) • Xcode at /Applications/Xcode.app/Contents/Developer • Xcode 12.2, Build version 12B45b • CocoaPods version 1.10.0 [✓] Chrome - develop for the web • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome [✓] Android Studio (version 4.1) • 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 1.8.0_242-release-1644-b3-6915495) [✓] VS Code (version 1.52.0) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension version 3.17.0 [✓] Connected device (2 available) • motorola one (mobile) • ZY323HWSM7 • android-arm64 • Android 10 (API 29) • Chrome (web) • chrome • web-javascript • Google Chrome 87.0.4280.88 • No issues found! ```

Flutter dependencies

Run flutter pub deps -- --style=compact and paste the output below:

Click To Expand ``` environment: sdk: ">=2.1.0 <3.0.0" dependencies: flutter: sdk: flutter firebase_core: "^0.5.3" # Newly reworked plugins covered by this migration guide: firebase_auth: "^0.18.4" cloud_firestore: "^0.14.4" cloud_functions: "^0.7.2" firebase_storage: "^5.2.0" firebase_messaging: ^7.0.3 # Updated to work with new core only plugins (no new changes): firebase_admob: "^0.10.3" firebase_analytics: "^6.3.0" firebase_database: "^4.4.0" firebase_dynamic_links: "^0.6.3" firebase_in_app_messaging: "^0.2.3" firebase_performance: "^0.4.3" flutter_local_notifications: ^3.0.2 ```

THANK YOU!!!

lidemin commented 3 years ago

Hi @danielgchap

Are you able to reproduce this issue constantly with any devices?

Our team is facing a similar issue, but only happens on some devices after we released it to Play Store.

And we can't get any logs from Crashlytics either, because Flutter Engine seems to be stuck when initialising Firebase core.

PS: We are following official migration guide , and only include FlutterFire upgrade in this release.

Thanks.

danielgchap commented 3 years ago

Hey @lidemin Yessir. I reproduced on a Nexus, Motorola and a Pixel 3. I noticed it first when it was a build I was running through internal testing via the app store. That's what led me to believe it was a --release build issue. I am following the official docs too. I'm not convinced it has anything to do with Firebase core. Chances are you have your 'await Firebase.initapp()' call as the second line in your main().

If you replaced it with something else like 'await SharedPrefs.init()' it would have an issue with that too.

I think it's because several migration guides and even the firebase-messaging guide calls for a new Application.kt file updates and only then did I start to see this issue.

I think the platform channel that Flutter is trying to generate to communicate with (for example..) libraries is having an issue. The logs lead me to believe that.

I have an issue opened with the Flutter repo too so hopefully they'll have some thoughts.

danielgchap commented 3 years ago

@lidemin just changed this and then did 'flutter run --release' and it works now...

dependencies {
          classpath 'com.android.tools.build:gradle:3.5.4'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath 'com.google.gms:google-services:4.3.3'
    }

I think this kind of validates my theory on the .kt files being changed to cover migration issues. I ended up down a research hole that led me to this:

https://stackoverflow.com/questions/62969917/how-do-i-fix-unexpected-element-queries-found-in-manifest

So I changed to a more 'stable' patch version (firebase-messaging asked for 3.5.0 I think, so I pushed it to 3.5.4). Might change it to the highest patch version from the link above and try that too.

Hope that helps in your case. Thanks

lidemin commented 3 years ago

Thanks @danielgchap for your detailed explanation.

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp();
  await initializeCrashlytics();
  FirebaseMessaging.onBackgroundMessage(handleBackgroundMessage);

  try {
    await RemoteConfigHelper.loadRemoteConfig();
  } catch (error, stackTrace) {
    // ignore: unawaited_futures
    FirebaseCrashlytics.instance.recordError(
        InsightException.make(error, additionalInfromation: "Error while initializing Remote config"), stackTrace,
        reason: "Error while initializing Remote config");
  }
  InAppPurchaseConnection.enablePendingPurchases();

  try {
    await FlutterDownloader.initialize();
  } catch (error, stackTrace) {
    // ignore: unawaited_futures
    FirebaseCrashlytics.instance.recordError(
        InsightException.make(error, additionalInfromation: "Error while initializing flutter downloader"), stackTrace,
        reason: "Error while initializing flutter downloader");
  }
  try {
    await initializeLocalNotificationManager();
  } catch (error, stackTrace) {
    // ignore: unawaited_futures
    FirebaseCrashlytics.instance.recordError(
        InsightException.make(error, additionalInfromation: "Error while initializing Local Notification manager"),
        stackTrace,
        reason: "Error while initializing Local Notification manager");
  }

  SystemChrome.setPreferredOrientations([
    DeviceOrientation.portraitUp,
    DeviceOrientation.portraitDown,
  ]).then((_) {
    runZonedGuarded<Future<Null>>(() async {
      try {
        final components = AppComponentBase.build(_appConfig, AppComponent(_appConfig));
        runApp(InsightApp(components, _appConfig));
      } catch (e, s) {
        await FirebaseCrashlytics.instance.recordError(
            InsightException.make(e, additionalInfromation: "Error while run app"), s,
            reason: "Error while run app");
        rethrow;
      }
    }, FirebaseCrashlytics.instance.recordError);
  });
}

the weird part to me is this setup and migration works for majority of our users, but not working for a few devices.

lidemin commented 3 years ago

Thanks @danielgchap

unfortunately, we are using it already

dependencies {
        classpath 'com.android.tools.build:gradle:3.5.4'
        classpath 'com.google.gms:google-services:4.3.4'  // Google Services plugin
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath 'com.google.firebase:firebase-crashlytics-gradle:2.2.0'
    }
danielgchap commented 3 years ago

@lidemin Hmmm. Maybe try a higher version? I'm not using firebase-crashlytics so I imagine any associated constraints with that pub will also come into play. Sorry brother. If I can help any further, lemme know. Don't forget, 99% of the time with programming, the answer is not an if, it's a when. You'll get it! Stay positive.

danielgchap commented 3 years ago

@lidemin Not sure if it will help at all but here's my android/build.gradle (not app/build.gradle)...

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'com.android.support:multidex:1.0.3'
    implementation 'com.google.android.gms:play-services-basement:17.5.0'
    implementation 'com.google.firebase:firebase-analytics:18.0.0'
    implementation 'com.google.firebase:firebase-messaging:21.0.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.1.0'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0'
}
lidemin commented 3 years ago

@lidemin Hmmm. Maybe try a higher version? I'm not using firebase-crashlytics so I imagine any associated constraints with that pub will also come into play. Sorry brother. If I can help any further, lemme know. Don't forget, 99% of the time with programming, the answer is not an if, it's a when. You'll get it! Stay positive.

lol. Thanks man. a few our team members have been stuck on this more than a week. The tricky part is, it is unreproducable, and Firebase logs does not come through either. That's why we suspect Firebase core has not been initialised properly.

danielgchap commented 3 years ago

@lidemin well, if you want to share any code, link me. Thank God we got a pretty good Flutter community now so we'll get it figured out.

markusaksli-nc commented 3 years ago

Closing this issue as solved based on https://github.com/FirebaseExtended/flutterfire/issues/4410#issuecomment-747141417

danielgchap commented 3 years ago

@lidemin UPloaded to play store. Download... still sticks on splash screen. I literally CHANGED NOTHING from last night. Came to project this morning.. Google Play Store build sticks on splash screen and local build now all of a sudden gets...

E/flutter ( 4874): [ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: MissingPluginException(No implementation found for method Firebase#initializeCore on channel plugins.flutter.io/firebase_core)
E/flutter ( 4874): #0      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:157)
E/flutter ( 4874): <asynchronous suspension>
E/flutter ( 4874): #1      MethodChannel.invokeListMethod (package:flutter/src/services/platform_channel.dart:345)
E/flutter ( 4874): <asynchronous suspension>
E/flutter ( 4874): #2      MethodChannelFirebase._initializeCore (package:firebase_core_platform_interface/src/method_channel/method_channel_firebase.dart:30)
E/flutter ( 4874): <asynchronous suspension>
E/flutter ( 4874): #3      MethodChannelFirebase.initializeApp (package:firebase_core_platform_interface/src/method_channel/method_channel_firebase.dart:75)
E/flutter ( 4874): <asynchronous suspension>
E/flutter ( 4874): #4      Firebase.initializeApp (package:firebase_core/src/firebase.dart:43)
E/flutter ( 4874): <asynchronous suspension>

@markusaksli-nc this is NOT resolved. Please don't be so hasty. It hasn't even been 24hrs. Thank you sir.

danielgchap commented 3 years ago

@lidemin @markusaksli-nc Upgraded to... dependencies { classpath 'com.android.tools.build:gradle:3.6.4' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" classpath 'com.google.gms:google-services:4.3.3' }

'flutter run --release' works and loads the app. Sending build to google play early release track now. Will let you know if it downloads and opens. Thanks all. Give me a few hours.

google-oss-bot commented 3 years ago

Hey @danielgchap. We need more information to resolve this issue but there hasn't been an update in 7 weekdays. I'm marking the issue as stale and if there are no new updates in the next 7 days I will close it automatically.

If you have more information that will help us get to the bottom of this, just add a comment!

hoanganhtran1010 commented 3 years ago

@danielgchap, did you solve this?

danielgchap commented 3 years ago

Hi there. Sorry. I upgraded all the firebase libraries which involved upgrading some other dependencies ( I think cupertino was involved somewhere) that will give you an error when you try to build it. Then I had to upgrade the actual flutter sdk which involved me moving branches to master rather than stable. I also ensured AndroidX compatibility.

I hope this helps! Now it works fine.