SudoPlz / sp-react-native-in-app-updates

An in-app updater for the native version of your react-native app.
MIT License
491 stars 66 forks source link

Failed to bind to the service on Android #183

Open Urolovshohjahon opened 4 months ago

Urolovshohjahon commented 4 months ago

Hi, everyone. I installed this package yesterday. But there is an error I couldn't fix. It works on iOS properly. But on Android throw below error while using checkNeedsUpdate method:

Error: sp-react-native-in-app-updates checkNeedsUpdate error: Error: com.google.android.play.core.appupdate.internal.zzy: Failed to bind to the service.

"react-native": "0.67.3", "sp-react-native-in-app-updates": "^1.4.0",

Device: Redmi Note 12

I found thrown place of error in package's native code:

appUpdateInfoTask.addOnFailureListener(err -> {
    resolutionPromise.reject("Exception", err.toString());
});

Here is code when I used package:

import {Platform} from 'react-native';
import SpInAppUpdates, {
  IAUUpdateKind,
  StartUpdateOptions,
  IAUInstallStatus,
} from 'sp-react-native-in-app-updates';

export const checkForUpdate = async () => {
  const inAppUpdates = new SpInAppUpdates(
    false, // isDebug
  );
  try {
    await inAppUpdates.checkNeedsUpdate().then(result => {
      try {
        if (result.shouldUpdate) {
          let updateOptions = {};
          if (Platform.OS === 'android') {
            updateOptions = {
              updateType: IAUUpdateKind.FLEXIBLE,
            };
          }
          if (Platform.OS === 'ios') {
            updateOptions = {
              title: 'Update available',
              message:
                'There is a new version of the app available on the App Store, do you want to update it?',
              buttonUpgradeText: 'Update',
              buttonCancelText: 'Cancel',
            };
          }
          inAppUpdates.addStatusUpdateListener(downloadStatus => {
            console.log('download status', downloadStatus);
            if (downloadStatus.status === IAUInstallStatus.DOWNLOADED) {
              console.log('downloaded');
              inAppUpdates.installUpdate();
              inAppUpdates.removeStatusUpdateListener(finalStatus => {
                console.log('final status', finalStatus);
              });
            }
          });
          inAppUpdates.startUpdate(updateOptions);
        }
      } catch (error) {
        console.error(error);
      }
    });
  } catch (error) {
    console.error(error);
  }
};

Please help me to fix it and continue work. Thanks for in advance!

poulimainfotech commented 4 months ago

did you fixed it ?, i got same error

Urolovshohjahon commented 4 months ago

did you fixed it ?, i got same error

no, can't fix, owners haven't responded yet

vinkumdev commented 4 months ago

Are you using real device? or simulator?

poulimainfotech commented 4 months ago

Are you using real device? or simulator?

both

vinkumdev commented 4 months ago

well, you should test on real device not on simulator.

Urolovshohjahon commented 4 months ago

well, you should test on real device not on simulator.

Real device returns same error, I toasted error. Device has Google Play service

vinkumdev commented 4 months ago

well, you should test on real device not on simulator.

Real device returns same error, I toasted error. Device has Google Play service

also just to confirm you building release apk not dwbug right?

vinkumdev commented 4 months ago

I came across this today, here is what i have done to make it working.

Urolovshohjahon commented 2 months ago

I came across this today, here is what i have done to make it working.

  • Installed the package and react-native-device-info.
  • Opened the app in the simulator and encountered the same error.
  • Referred to the package documentation and found additional information.
  • Built the app for release.
  • Uploaded the AAB for internal sharing, installed, or updated the app.
  • Made some changes and uploaded a new AAB.
  • Checked on the Play Store that an update was available but did not hit update.
  • Opened the app and updated it from within the app.

Well done, it worked after doing that guidline