britannio / in_app_review

A Flutter plugin for showing the In-App Review/System Rating pop up on Android, IOS, and MacOS. It makes it easy for users to rate your app.
311 stars 81 forks source link

Fatal Exception: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.content.Context.getPackageName()' on a null object reference #23

Closed 04tushar closed 3 years ago

04tushar commented 3 years ago

We are getting the above logs in Firebase Crashlytics as fatal issue.

britannio commented 3 years ago

Can you provide any more info?

This is the only piece of code calling getPackageName() and context is being null checked to prevent this. https://github.com/britannio/in_app_review/blob/master/in_app_review/android/src/main/java/dev/britannio/in_app_review/InAppReviewPlugin.java#L200-L209

04tushar commented 3 years ago

Below is the code we integrated into our app:

final InAppReview _inAppReview = InAppReview.instance; String _appStoreId = ''; String _microsoftStoreId = ''; bool _isAvailable;

@override void initState() { super.initState();

WidgetsBinding.instance.addPostFrameCallback((_) {
  _inAppReview
      .isAvailable()
      .then(
        (bool isAvailable) => setState(
          () => _isAvailable = isAvailable && !Platform.isAndroid,
        ),
      )
      .catchError((_) => setState(() => _isAvailable = false));
});

}

void _setAppStoreId(String id) => _appStoreId = id;

void _setMicrosoftStoreId(String id) => _microsoftStoreId = id;

Future _requestReview() => _inAppReview.requestReview();

Future _openStoreListing() => _inAppReview.openStoreListing( appStoreId: _appStoreId );

britannio commented 3 years ago

Did Crashlytics provide any more info like a stacktrace? Do you understand what the code you copied is doing? Are you making a Windows app with Flutter?

britannio commented 3 years ago

Without further information, I'm not sure how I can help or if there's even anything that I need to do. Is there only one event in Crashlytics or are there many. Do they follow a pattern?

04tushar commented 3 years ago

Please find below stacktrace :

Fatal Exception: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.content.Context.getPackageName()' on a null object reference at android.content.ComponentName.(ComponentName.java:130) at android.content.Intent.(Intent.java:5780) at com.google.android.play.core.review.c.launchReviewFlow(c.java:4) at dev.britannio.in_app_review.InAppReviewPlugin.launchReviewFlow(InAppReviewPlugin.java:180) at dev.britannio.in_app_review.InAppReviewPlugin.access$200(InAppReviewPlugin.java:30) at dev.britannio.in_app_review.InAppReviewPlugin$2.onComplete(InAppReviewPlugin.java:169) at com.google.android.play.core.tasks.a.run(a.java:23) at android.os.Handler.handleCallback(Handler.java:790) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:164) at android.app.ActivityThread.main(ActivityThread.java:6518) at java.lang.reflect.Method.invoke(Method.java) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)

We are build android app with flutter.

britannio commented 3 years ago

Thanks for the stacktrace! I've found a potential cause for this and I'll release a fix shortly.

britannio commented 3 years ago

I've just released in_app_review: 2.0.1-dev

04tushar commented 3 years ago

ok

04tushar commented 3 years ago

Getting below error while upgrading version of the plugin:

Because in_app_review >=2.0.1 depends on in_app_review_platform_interface ^2.0.2 which depends on plugin_platform_interface ^2.0.0, in_app_r eview >=2.0.1 requires plugin_platform_interface ^2.0.0. And because speech_to_text_platform_interface 1.4.2 depends on plugin_platform_interface ^1.0.1 and no versions of speech_to_text_platform_i nterface match >1.4.2 <2.0.0, in_app_review >=2.0.1 is incompatible with speech_to_text_platform_interface ^1.4.2. And because speech_to_text 3.1.0 depends on speech_to_text_platform_interface ^1.4.2 and no versions of speech_to_text match >3.1.0 <4.0.0, in_app_review >=2.0.1 is incompatible with speech_to_text ^3.1.0. So, because stage_flutter depends on both speech_to_text ^3.1.0 and in_app_review ^2.0.1, version solving failed.

britannio commented 3 years ago

@04tushar https://github.com/csdcorp/speech_to_text/issues/179 this is the issue.