[Android]: loginUnidentifiedUser never executes with existing Intercom user session.
After we updated to intercom_flutter: ^7.2.0, our android build started to have this weird behavior where once the app is closed, the app would be stuck on the splash screen forever once it's reopened.
We spent days locating the root cause of this and finally figured out this was because of the intercom. There is no error message in the log which makes it super hard to locate the issue.
If we remove all intercom code from our flutter project, our android app works fine.
We already updated our android/app/build.gradle dependency to
implementation 'io.intercom.android:intercom-sdk:12.2+'
But the issue persists.
From the log of flutter run -v --release, it seems like after the app is closed and reopened, the Flutter engine never kicks in, something broke before the flutter engine runs and stopped the flutter layer from running, making the android app stays on the splash screen.
@vitable-dev the version intercom_flutter: 7.2.0 is released recently on May 12, 2022, which uses Intercom Android SDK version 12.2.2
Does this happens only with a version 7.2.0? or with older versions as well.
We already updated our android/app/build.gradle dependency to
implementation 'io.intercom.android:intercom-sdk:12.2+'
Why you have added this dependency in your android build.gradle? This is not required.
I have tested the example app and there is no issue with version 7.2.0. Could you please give it a try as well?
Which Flutter SDK version are you using? I tested it with 3.0.0
Turns out the Android SDK was failing silently on
await Intercom.instance.loginUnidentifiedUser();
^ We do this on app start and this is somehow stopping the flutter VM from starting.
We changed it to the following and it solved the problem.
await Intercom.instance.logout();
await Intercom.instance.loginUnidentifiedUser();
We spent a lot of time on this and the reason for this problem being so hard to find is that the intercom SDK is failing silently without any log or warning, please address this.
The methods loginIdentifiedUser, loginUnidentifiedUser are used to log in the user in Intercom.
These methods have a parameter called statusCallback which was added in SDK version 12.1.0.
So you can use this parameter to check the response of these methods.
If the user is already logged in to Intercom then there will be an error.
@vitable-dev
I tested the loginUnidentifiedUser method.
TextButton(
onPressed: () async {
await Intercom.instance.loginUnidentifiedUser(
statusCallback: IntercomStatusCallback(
onSuccess: () {
print("Success");
},
onFailure: (error) {
print(error.toString());
},
),
);
print("Statement after login unidentified user");
},
child: Text('Login'),
),
When I click the first time on the "Login" button in Android then I see the 2 prints on the console:
I/flutter (11345): Success
I/flutter (11345): Statement after login unidentified user
If I click again on the "Login" button, there is no console output. Neither from onFailure nor the last statement. So it means if there is already an unidentified user logged in then Intercom on Android is not returning any callback result. Even not working with the latest Intercom Android SDK version 12.3.0.
But this is working fine on iOS. Every time I click on the "Login" button, it gives the success callback. And this success callback is for the same user. I checked the Intercom. No new user is created every time until you log out.
iOS console output:
flutter: Success
flutter: Statement after login unidentified user
flutter: Success
flutter: Statement after login unidentified user
flutter: Success
flutter: Statement after login unidentified user
flutter: Success
flutter: Statement after login unidentified user
flutter: Success
flutter: Statement after login unidentified user
I will report this issue to Intercom. I also request you to do the same. This will prioritize the issue.
Related issue https://github.com/v3rm0n/intercom_flutter/issues/238
I have already reported the issue to Intercom and they verified that it is an issue in the current SDK version. But this will take time to get resolved.
To set expectations upfront, an issue like this one might not be looked at for a few weeks, or possibly months. The timeline is based on the team's existing backlog of issues and upcoming feature releases, which is subject to change. Till then the team suggested you to use the workaround you mentioned (calling the logout method before calling login again)
With that being said, thanks for flagging it with us.
So for now the only solution is to call logout before that:
await Intercom.instance.logout();
await Intercom.instance.loginUnidentifiedUser();
Same issue with the latest Intercom SDK v14.
I am also getting same issue on android. currently I don't have a mac so did not test it out.
@deepak786 I am having a similar problem even without any session at all... My API keys seems ok, because if I pass any invalid data it will give another error.
My app starts and only calls this:
await Intercom.instance.initialize(
"XXXXXXXX",
androidApiKey: "XXXXXXXXXXXXXXXX",
iosApiKey: "XXXXXXXXXXXX",
);
await Intercom.instance.logout();
await Intercom.instance.loginUnidentifiedUser();
And I get this:
Failed to register or update user: {"type":"error.list","request_id":"0003e2fkuanumsdq6sng","errors":[{"code":"not_found","message":"Resource Not Found"}]}
@igoracmelo It seems that your issue is similar to https://github.com/v3rm0n/intercom_flutter/issues/223 But there was no solution at that time and also according to Intercom, the error was not from their SDK.
Now you also have a similar issue so I need more information to reproduce this and to report it back to Intercom.
The issue is fixed in Intercom Android SDK v14.0.5 which is used in intercom_flutter: 7.6.5.
I have tested the following:
TextButton(
onPressed: () async {
await Intercom.instance.loginUnidentifiedUser(
statusCallback: IntercomStatusCallback(
onSuccess: () {
print("Success");
},
onFailure: (error) {
print(error.toString());
},
),
);
print("Statement after login unidentified user");
},
child: Text('Login'),
),
Console:
I/flutter (8473): Success
I/flutter (8473): Statement after login unidentified user
I/flutter ( 8473): errorCode: 3002, errorMessage: Failed to register user. We already have a registered user. If you are attempting to register a new user, call logout() before this. If you are attempting to register an identified user call: registerIdentifiedUser(Registration)
I/flutter ( 8473): Statement after login unidentified user
I/flutter ( 8473): errorCode: 3002, errorMessage: Failed to register user. We already have a registered user. If you are attempting to register a new user, call logout() before this. If you are attempting to register an identified user call: registerIdentifiedUser(Registration)
I/flutter ( 8473): Statement after login unidentified user
So now if there is a loggedIn user, calling loginUnidentifiedUser again will result in failure callback and the further code will continue to run.
@deepak786 how can this issue be fixed and closed with the example code above, when calling loginUnidentifiedUser still throws an error on Android? Try opening the chat flow with it, Javascript SDK library shows error page instead of the chat where you keep going.
@LugonjaAleksandar Please share the reproducible sample. Also which intercom_flutter version are you using?