Skip to content

InAppUpdate.checkForUpdate 10 crashes from 10 user #115

@ProZhar

Description

@ProZhar

In my case when:

  • run debug mode - works
  • run release mode - works
  • download from internal app testing in Google Play - works

But when I added the app bundle to release, Google Play rejected my app.
I installed crashlytics and received a report today about 10 crashes on 10 users

StandardMethodCodec.decodeEnvelope (message_codecs.dart:652)
MethodChannel._invokeMethod (platform_channel.dart:310)

InAppUpdate.checkForUpdate (in_app_update.dart:62)

IAUpdateService.init (iaupdate_service.dart:11)
GetInstance.putAsync (get_instance.dart:62)
.main (main.dart:69)

Key - flutter_error_exception
Value - PlatformException(TASK_FAILURE, Failed to bind to the service., null, null)

My code

void main() async {
  WidgetsBinding widgetsBinding = WidgetsFlutterBinding.ensureInitialized();

  lgS.i('FlutterNativeSplash.preserve()\n'
      '- will be removed in HomeController');
  FlutterNativeSplash.preserve(widgetsBinding: widgetsBinding);

  // Orientation
  await SystemChrome.setPreferredOrientations([
    DeviceOrientation.portraitUp,
    DeviceOrientation.portraitDown,
  ]);

  // Firebase
  await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform);
  await Get.putAsync<AnalyticsService>(() => AnalyticsService().init());
  await Get.putAsync<CrashlyticsService>(() => CrashlyticsService().init());

  await Get.putAsync<IAUpdateService>(() => IAUpdateService().init());

  runApp(
    GetMaterialApp(
      debugShowCheckedModeBanner: false,
      title: Get.find<ConfigService>().title,
      // Localization
      locale: Get.find<SettingsService>().model.locale,
      fallbackLocale: L.fallbackLocale,
      translationsKeys: AppTranslation.translations,
      // Theming
      theme: Themes.lightThemeData,
      darkTheme: Themes.darkThemeData,
      themeMode: Get.find<SettingsService>().model.themeMode,
      // Routing
      initialRoute: AppPages.INITIAL,
      getPages: AppPages.routes,
      // defaultTransition: Transition.fadeIn, //TODO: определить позже defaultTransition
      // EasyLoading package
      builder: EasyLoading.init(),
    ),
  );
}

class IAUpdateService extends GetxService {
  late final AppUpdateInfo _updateInfo;

  Future<IAUpdateService> init() async {
    _updateInfo = await InAppUpdate.checkForUpdate();
    lgS.i(_updateInfo);

    return this;
  }

  @override
  void onReady() {
    if (_updateInfo.updateAvailability == UpdateAvailability.updateAvailable) {
      if (_updateInfo.flexibleUpdateAllowed) {
        lgS.i('InAppUpdate.startFlexibleUpdate()');
        InAppUpdate.startFlexibleUpdate().then((result) {
          if (result == AppUpdateResult.success) {
            Get.snackbar(
              "",
              "An update has just been downloaded.",
              duration: const Duration(hours: 1),
              mainButton: TextButton(
                child: const Text("Install"),
                onPressed: () async =>
                    await InAppUpdate.completeFlexibleUpdate(),
              ),
            );
          } else {
            //TODO обработать другие enum в analytics & crashlytics
            lgS.w(result);
          }
        }).catchError((e) {
          //TODO сделать вывод в analytics & crashlytics
          lgS.e(e, error: e);
        });
      } else if (_updateInfo.immediateUpdateAllowed) {
        lgS.i('InAppUpdate.performImmediateUpdate()');
        InAppUpdate.performImmediateUpdate()
            .then((value) => null)
            .catchError((e) {
          //TODO сделать вывод в analytics & crashlytics
          lgS.e(e, error: e);
        });
      } else {
        lgS.w('flexibleUpdateAllowed & immediateUpdateAllowed != true');
      }
    } else {
      lgS.w('updateAvailability != UpdateAvailability.updateAvailable');
    }
    super.onReady();
  }
}

Maybe this is because await InAppUpdate.checkForUpdate() is used before running the application runApp(MyApp()?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions