getphyllo / phyllo-connect-flutter

MIT License
1 stars 4 forks source link

[FATAL Crash] - java.lang.IllegalArgumentException: Context must not be null. #18

Closed ariefwijaya closed 1 year ago

ariefwijaya commented 2 years ago

Problem

I keep getting this crash report by Firebase Crashlytics that caused by phyllo. I can't to reproduce it because the application crashed and had no navigation logs.

Error Logs

Fatal Exception: java.lang.RuntimeException: Unable to start activity ComponentInfo{id.bintango/com.getphyllo.activities.ConnectMainActivity}: java.lang.IllegalArgumentException: Context must not be null.
       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3502)
       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3656)
       at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
       at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:140)
       at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:100)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2210)
       at android.os.Handler.dispatchMessage(Handler.java:107)
       at android.os.Looper.loop(Looper.java:241)
       at android.app.ActivityThread.main(ActivityThread.java:7844)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:512)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:986)

Caused by java.lang.IllegalArgumentException: Context must not be null.
       at com.segment.analytics.Analytics.with(Analytics.java:173)
       at com.getphyllo.utils.LogUtils.LOGD(SourceFile:16)
       at com.getphyllo.activities.ConnectMainActivity.onCreate(SourceFile:14)
       at android.app.Activity.performCreate(Activity.java:7984)
       at android.app.Activity.performCreate(Activity.java:7973)
       at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1307)
       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3473)
       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3656)
       at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
       at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:140)
       at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:100)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2210)
       at android.os.Handler.dispatchMessage(Handler.java:107)
       at android.os.Looper.loop(Looper.java:241)
       at android.app.ActivityThread.main(ActivityThread.java:7844)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:512)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:986)  

Current Implementation

This is how we connect to phyllo:

 final res = await restApi.get(ApiPath.gocreatorGetConnect,
        overrideBaseUrl: Env.urlServicePhyllo,
        body: {"platform_id": platform.name});

    final connectConfig = GocreatorConnectModel.fromJson(
        res.data['phyllo_config'] as Map<String, dynamic>);

    PhylloEnvironment choosenEnvironment = PhylloEnvironment.development;
    if (connectConfig.environment == PhylloEnvironment.production.name) {
      choosenEnvironment = PhylloEnvironment.production;
    } else if (connectConfig.environment == PhylloEnvironment.sandbox.name) {
      choosenEnvironment = PhylloEnvironment.sandbox;
    }
    phyllo.initialize(PhylloConfig(
      clientDisplayName: connectConfig.clientDisplayName,
      environment: choosenEnvironment,
      userId: connectConfig.userId,
      token: connectConfig.token,
      workPlatformId: connectConfig.workPlatformId,
    ));

    phyllo.onConnectCallback(
        onAccountConnected: onAccountConnected,
        onAccountDisconnected: onAccountDisconnected,
        onTokenExpired: onTokenExpired,
        onExit: onExit);

    phyllo.open();
erpankajpatel commented 1 year ago

@ariefwijaya we have update version with phyllo_connect: ^0.3.1 , Please try this one let me know .hope it will resolve your issue .

ariefwijaya commented 1 year ago

@erpankajpatel We've updated to 0.3.1 and changed the bit implementation as requested by the Phyllo Team. but still having the same problem. here is the new log from crashlytics:

Fatal Exception: java.lang.RuntimeException: Unable to start activity ComponentInfo{id.bintango/com.getphyllo.activities.ConnectWebActivity}: java.lang.NullPointerException
       at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2919)
       at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3054)
       at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
       at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
       at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1814)
       at android.os.Handler.dispatchMessage(Handler.java:106)
       at android.os.Looper.loop(Looper.java:280)
       at android.app.ActivityThread.main(ActivityThread.java:6706)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)

Download Full Log here: id.bintango_issue_509296a595e5cfe841c69e71ea6dda35_crash_session_63D3930D01BC00016D991ACFB86B9AF4_DNE_0_v2_stacktrace.txt

Flutter Version:

Flutter Doctor

``` [✓] Flutter (Channel stable, 3.3.10, on macOS 13.1 22C65 darwin-arm, locale en-ID) • Flutter version 3.3.10 on channel stable at /Users/ariefwijaya/fvm/versions/stable • Upstream repository https://github.com/flutter/flutter.git • Framework revision 135454af32 (6 weeks ago), 2022-12-15 07:36:55 -0800 • Engine revision 3316dd8728 • Dart version 2.18.6 • DevTools version 2.15.0 [✓] Android toolchain - develop for Android devices (Android SDK version 33.0.1) • Android SDK at /Users/ariefwijaya/Library/Android/sdk • Platform android-33, build-tools 33.0.1 • ANDROID_HOME = /Users/ariefwijaya/Library/Android/sdk • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866) • All Android licenses accepted. [✓] Xcode - develop for iOS and macOS (Xcode 14.2) • Xcode at /Applications/Xcode.app/Contents/Developer • Build 14C18 • CocoaPods version 1.11.3 [✓] Android Studio (version 2021.3) • Android Studio at /Applications/Android Studio.app/Contents • Flutter plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/6351-dart • Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866) [✓] VS Code (version 1.75.0-insider) • VS Code at /Applications/Visual Studio Code - Insiders.app/Contents • Flutter extension version 3.58.0 [✓] Connected device (1 available) • Redmi Note 7 (mobile) • 85b9c4e6 • android-arm64 • Android 13 (API 33) [✓] HTTP Host Availability • All required HTTP hosts are available • No issues found! ````

Updated Implementation

  final res = await restApi.get(ApiPath.gocreatorGetConnect,
        overrideBaseUrl: Env.urlServicePhyllo,
        body: {"platform_id": platform.name});

    final connectConfig = GocreatorConnectModel.fromJson(
        res.data['phyllo_config'] as Map<String, dynamic>);

    PhylloEnvironment choosenEnvironment = PhylloEnvironment.development;
    if (connectConfig.environment == PhylloEnvironment.production.name) {
      choosenEnvironment = PhylloEnvironment.production;
    } else if (connectConfig.environment == PhylloEnvironment.sandbox.name) {
      choosenEnvironment = PhylloEnvironment.sandbox;
    }

    final lang = sharedPreferences.getString('language_code') ??
        AppSetting.defaultLanguage.languageCode;

    await phyllo.initialize({
      "clientDisplayName": connectConfig.clientDisplayName,
      "environment": choosenEnvironment.name,
      "userId": connectConfig.userId,
      "token": connectConfig.token,
      "workPlatformId": connectConfig.workPlatformId,
      "language": lang
    });

    phyllo.open();

    phyllo.onConnectCallback(
        onAccountConnected: onAccountConnected,
        onAccountDisconnected: onAccountDisconnected,
        onTokenExpired: onTokenExpired,
        onExit: onExit,
        onConnectionFailure: onConnectionFailure);

Device

image
erpankajpatel commented 1 year ago

@ariefwijaya in flutter package we had updated with version 0.3.3 , i would suggest please update with latest one if you can , meanwhile w e are looking into your issue . keep you posted .

chiragphyllo commented 1 year ago

Hi @ariefwijaya, we checked the updated implementation above. Can you specify which environment you are passing in config for initialising the SDK?

ariefwijaya commented 1 year ago

@chiragphyllo Hi, We are passing PhylloEnvironment.production .

ariefwijaya commented 1 year ago

@erpankajpatel Ok Thanks, We will update it. Any idea why it's happening to some users or is it just intermittent crash?