Onesignal-flutter-sdk: Error sending tags Android

Created on 22 May 2019  路  4Comments  路  Source: OneSignal/OneSignal-Flutter-SDK

Error when i tried to send a tag on android device the app crashes:

Error:
java.lang.RuntimeException: Methods marked with @UiThread must be executed on the main thread. Current thread: Thread-7 E/AndroidRuntime( 6239): at io.flutter.embedding.engine.FlutterJNI.ensureRunningOnMainThread(FlutterJNI.java:605) E/AndroidRuntime( 6239): at io.flutter.embedding.engine.FlutterJNI.invokePlatformMessageResponseCallback(FlutterJNI.java:556) E/AndroidRuntime( 6239): at io.flutter.embedding.engine.dart.DartMessenger$Reply.reply(DartMessenger.java:131) E/AndroidRuntime( 6239): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler$1.success(MethodChannel.java:225) E/AndroidRuntime( 6239): at com.onesignal.flutter.OSFlutterChangeTagsHandler.onSuccess(OneSignalTagsController.java:43) E/AndroidRuntime( 6239): at com.onesignal.UserStateSynchronizer$4.onSuccess(UserStateSynchronizer.java:320) E/AndroidRuntime( 6239): at com.onesignal.OneSignalRestClient$5.run(OneSignalRestClient.java:208) E/AndroidRuntime( 6239): at java.lang.Thread.run(Thread.java:761)

Please help me, how do i send a tag in main thread from flutter?

Need More Information

Most helpful comment

Okay, I ran through the same issue! Changing Flutter channel to 'stable' fixed this issue.Currently I am with Flutter v1.5.4-hotfix.2. Working well now!

All 4 comments

Well, the thing is that the process is executed succesfully but something that onesignal return, it returns in async mode or something and blow up the app.
I edited the OneSignalTagsController.java to catch the exception that returns and just log error into console and then the app doesn't crash.
Line 39 void:

public void onSuccess(JSONObject tags) {
if (this.replySubmitted.getAndSet(true))
return;

    try {
        this.result.success(OneSignalSerializer.convertJSONObjectToHashMap(tags));
    } catch (JSONException exception) {
        this.result.error("onesignal", "Encountered an error serializing tags into hashmap: " + exception.getMessage() + "\n" + exception.getStackTrace(), null);
    } catch (Exception Ex) { /**CATCH EXCEPTION ADDED**/
        Log.e("onesignal", "Encountered an error changing tags(" + tags.toString() + "): " + Ex.getLocalizedMessage());
    }
}

Please follow our issue template so we can better help you. Thanks

Okay, I ran through the same issue! Changing Flutter channel to 'stable' fixed this issue.Currently I am with Flutter v1.5.4-hotfix.2. Working well now!

@anish-adm Thanks for your input. Will close this issue for now. Feel free to reopen if the issue or a related issue persists

Was this page helpful?
0 / 5 - 0 ratings

Related issues

TarekkMA picture TarekkMA  路  10Comments

Holofox picture Holofox  路  8Comments

bhoominn picture bhoominn  路  3Comments

royibernthal picture royibernthal  路  8Comments

Bwolfs2 picture Bwolfs2  路  5Comments