Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

InAppUpdate.checkForUpdate 10 crashes from 10 user #115

Open
ProZhar opened this issue Nov 3, 2023 · 1 comment
Open

InAppUpdate.checkForUpdate 10 crashes from 10 user #115

ProZhar opened this issue Nov 3, 2023 · 1 comment

Comments

@ProZhar
Copy link

ProZhar commented Nov 3, 2023

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()?

@jonasbark
Copy link
Owner

Did you try changing it according to your assumption?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants