RodrigoSMarques / flutter_branch_sdk

Flutter Plugin for create deep link using Branch Metrics SDK. This plugin provides a cross-platform (iOS, Android, Web).
https://branch.io
MIT License
100 stars 90 forks source link

PlatformException - NullPointerException #277

Closed frsisalima closed 9 months ago

frsisalima commented 10 months ago

Describe the bug We have correctly implemented this library and have deployed it in our Flutter app, but we are receiving an error in Crashlytics when initializing the SDK.

Fatal Exception: io.flutter.plugins.firebase.crashlytics.FlutterError: PlatformException(error, Attempt to invoke virtual method 'java.lang.Class java.lang.Object.getClass()' on a null object reference, null, java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Class java.lang.Object.getClass()' on a null object reference at z1.b.H(Unknown Source:289) at z1.b.onMethodCall(Unknown Source:455) at xe.k$a.a(Unknown Source:17) at le.c.l(Unknown Source:18) at le.c.m(Unknown Source:40) at le.c.i(Unknown Source:0) at le.b.run(Unknown Source:12) at android.os.Handler.handleCallback(Handler.java:942) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loopOnce(Looper.java:211) at android.os.Looper.loop(Looper.java:300) at android.app.ActivityThread.main(ActivityThread.java:8294) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:580) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1028) ) at StandardMethodCodec.decodeEnvelope(message_codecs.dart:651) at MethodChannel._invokeMethod(platform_channel.dart:322) at FlutterBranchSdkMethodChannel.init(flutter_branch_sdk_method_channel.dart:35) at FlutterBranchSdk.init(flutter_branch_sdk.dart:12) at DynamicLinkController.onInit(dynamic_link_controller.dart:43)

To Reproduce We don't know how to reproduce it since it seems this error occurs for some users - (Until now 250 users with 320 logs).

Smartphone (Please complete the following information. remove session if not platform):

RodrigoSMarques commented 10 months ago

Does your project use any package that made changes to the MainActivity of the Native Android project?

What packages are used in your project?

frsisalima commented 10 months ago

@RodrigoSMarques we have many additional packages; I will share a list of them along with my MainActivity file and the AndroidManifest.xml content

environment:
  sdk: ">=2.12.0 <3.0.0"

dependencies:
  flutter:
    sdk: flutter
  flutter_localizations:
    sdk: flutter
  pointycastle: ^3.6.2
  just_the_tooltip:
    git:
      url: https://github.com/frsisalima/just_the_tooltip.git
      ref: main
  vibration: ^1.8.3
  disk_space_plus: ^0.2.3
  flutter_branch_sdk: ^7.0.2
  flutter_native_splash: ^2.2.16
  flutter_sfsymbols: ^2.0.0
  uni_links: ^0.5.1
  advertising_id: ^2.3.0
  firebase_instance_id: ^1.0.0
  flutter_apns_only: ^1.6.0
  audio_service: ^0.18.12
  just_audio: ^0.9.34
  shared_preferences: ^2.0.15
  store_redirect: ^2.0.1
  flutter_facebook_auth: ^5.0.6
  scrollable_positioned_list: ^0.3.5
  flutter_datetime_picker_plus: ^2.0.1
  awesome_notifications: ^0.8.2
  image_picker: ^0.8.6
  image_cropper: ^3.0.1
  path_provider: ^2.0.11
  flutter_cache_manager: 3.3.1
  cached_network_image: 3.3.0
  firebase_analytics: ^10.4.4
  firebase_messaging: ^14.1.3
  firebase_dynamic_links: ^5.0.7
  url_launcher: ^6.1.7
  page_view_indicators: ^2.0.0
  device_info: ^2.0.3
  package_info: ^2.0.2
  country_code_picker: ^2.0.2
  google_sign_in: ^5.4.2
  webview_flutter: ^3.0.4
  sign_in_with_apple: 5.0.0
  intl_utils: ^2.8.3
  carousel_slider: ^4.1.1
  uuid: ^3.0.7
  mixpanel_flutter: ^2.1.1
  get: 4.6.5
  permission_handler: ^10.2.0
  share_plus: ^7.0.2
  flutter_dialogs: ^3.0.0
  flutter_timezone: ^1.0.4
  chewie: ^1.7.1
  video_player: ^2.8.1
  subtitle_wrapper_package: ^2.2.0
  hive: ^2.2.3
  hive_flutter: ^1.1.0
  amplitude_flutter: ^3.15.0
  fk_user_agent: ^2.1.0
  firebase_remote_config: ^3.0.6
  firebase_core: 2.15.0
  braze_plugin: ^3.0.0
  lottie: 2.0.0
  wakelock_plus: ^1.1.1
  app_tracking_transparency: ^2.0.3
  percent_indicator: ^4.2.2
  firebase_crashlytics: ^3.0.6
  flutter_keyboard_visibility: ^5.4.0
  connectivity: ^3.0.6
  facebook_app_events: ^0.18.3
  scroll_date_picker:
    git:
      url: https://github.com/frsisalima/scroll_date_picker.git
      ref: master
  flutter_tags_x: ^1.1.0
  screenshot_callback:
    git:
      url: https://github.com/meeefiu/flutter_screenshot_callback.git
      ref: master
  storyly_flutter:
    git:
      url: https://github.com/lazarohcm/storyly-mobile.git
      path: flutter/storyly_flutter/
      ref: fix-flutter-android-storyly-view-factory
  in_app_review: ^2.0.4
  flutter_app_badger: ^1.5.0
  badges: ^2.0.3
  in_app_purchase: 3.1.11
  dio: ^5.3.2
  archive: 3.3.0

` <application android:name="${applicationName}" android:usesCleartextTraffic="true" android:label="@string/app_name" android:enableOnBackInvokedCallback="true" android:icon="@mipmap/ic_launcher">

    <meta-data
            android:name="AdaptyPublicSdkKey"
            android:value="..." />

    <provider
        android:name="androidx.work.impl.WorkManagerInitializer"
        android:authorities="${applicationId}.workmanager-init"
        android:enabled="false"
        android:exported="false" />

    <activity
        android:name="com.yalantis.ucrop.UCropActivity"
        android:screenOrientation="portrait"
        android:exported="true"
        android:theme="@style/Theme.AppCompat.Light.NoActionBar"/>

    <activity
        android:name=".MainActivity"
        android:launchMode="singleTask"
        android:theme="@style/LaunchTheme"
        android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
        android:hardwareAccelerated="true"
        android:screenOrientation="portrait"
        android:exported="true"
        android:windowSoftInputMode="adjustResize">

        <intent-filter>
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />
            <data android:scheme="com.storybook" android:host="storybook-app.com" />
            <data android:scheme="com.storybook" android:host="open" />

        </intent-filter>

        <intent-filter android:autoVerify="true">
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />
            <data android:scheme="https" android:pathPrefix="/app/" android:host="get.storybook-app.com" />
        </intent-filter>

        <!-- Branch App Links - Live App -->
        <intent-filter android:autoVerify="true">
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />
            <data android:scheme="https" android:host="storybookapp.app.link" />
            <data android:scheme="https" android:host="storybookapp-alternate.app.link" />
        </intent-filter>
        <!-- Branch App Links - Test App -->
        <intent-filter android:autoVerify="true">
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />
            <data android:scheme="https" android:host="storybookapp.test-app.link" />
            <!-- example-alternate domain is required for App Links when the Journeys/Web SDK and Deepviews are used inside your website.  -->
            <data android:scheme="https" android:host="storybookapp-alternate.test-app.link" />
        </intent-filter>

        <meta-data
                android:name="io.flutter.embedding.android.NormalTheme"
                android:resource="@style/NormalTheme"
        />
        <intent-filter>
            <action android:name="android.intent.action.MAIN"/>
            <category android:name="android.intent.category.LAUNCHER"/>
        </intent-filter>

        <intent-filter>
            <action android:name="FLUTTER_NOTIFICATION_CLICK" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>

        <intent-filter  android:autoVerify="true">
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />
            <data android:scheme="https"
                android:host="storybook.onelink.me"
                android:pathPrefix="/hBlc" />
        </intent-filter>
    </activity>
    <meta-data android:name="com.facebook.sdk.AutoLogAppEventsEnabled"
        android:value="true"/>
    <meta-data android:name="com.facebook.sdk.AutoInitEnabled"
               android:value="true"/>

    <meta-data android:name="com.facebook.sdk.ApplicationId"
        android:value="@string/facebook_app_id"/>
    <meta-data android:name="com.facebook.sdk.ClientToken" android:value="@string/facebook_client_token"/>

    <activity android:name="com.facebook.FacebookActivity"
        android:configChanges=
            "keyboard|keyboardHidden|screenLayout|screenSize|orientation"
        android:label="@string/app_name" />

    <activity
        android:name="com.facebook.CustomTabActivity"
        android:exported="true">
        <intent-filter>
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />
            <data android:scheme="@string/fb_login_protocol_scheme" />
        </intent-filter>
    </activity>

    <activity
        android:name="com.aboutyou.dart_packages.sign_in_with_apple.SignInWithApplePlugin"
        android:exported="true">
        <intent-filter>
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />

            <data android:scheme="signinwithapple" />
            <data android:path="callback" />
        </intent-filter>
    </activity>

    <service android:name="com.braze.push.BrazeFirebaseMessagingService"
             android:exported="false">
        <intent-filter>
            <action android:name="com.google.firebase.MESSAGING_EVENT" />
        </intent-filter>
    </service>

    <meta-data
            android:name="flutterEmbedding"
            android:value="2" />

    <!-- ADD THIS "SERVICE" element -->
    <service android:name="com.ryanheise.audioservice.AudioService"
        android:foregroundServiceType="mediaPlayback"
        android:exported="true" tools:ignore="Instantiatable">
        <intent-filter>
            <action android:name="android.media.browse.MediaBrowserService" />
        </intent-filter>
    </service>

    <!-- ADD THIS "RECEIVER" element -->
    <receiver android:name="com.ryanheise.audioservice.MediaButtonReceiver"
        android:exported="true" tools:ignore="Instantiatable">
        <intent-filter>
            <action android:name="android.intent.action.MEDIA_BUTTON" />
        </intent-filter>
    </receiver>

    <meta-data android:name="io.branch.sdk.BranchKey" android:value="..." />
    <meta-data android:name="io.branch.sdk.BranchKey.test" android:value="..." />
    <meta-data android:name="io.branch.sdk.TestMode" android:value="false" />
</application>`
public class MainActivity extends com.ryanheise.audioservice.AudioServiceActivity {

  @Override
  public void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
   // getApplication().registerActivityLifecycleCallbacks(new AppboyLifecycleCallbackListener());
  }

  @Override
  public void configureFlutterEngine(@NonNull FlutterEngine flutterEngine) {
    super.configureFlutterEngine(flutterEngine);
      GeneratedPluginRegistrant.registerWith(flutterEngine);
  }

}
RodrigoSMarques commented 9 months ago

@frsisalima

version 7.0.3 that includes a consistency to handle application crashes if getClass() is null

RodrigoSMarques commented 9 months ago

Fixed in version 7.0.3