ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
Sentry Issue: WORDPRESS-ANDROID-2Y5B
ViewRootImpl$CalledFromWrongThreadException: Only the original thread that created a view hierarchy can touch its views.
at org.wordpress.android.login.LoginBaseFormFragment.endProgress(LoginBaseFormFragment.java:273)
at org.wordpress.android.ui.accounts.signup.SignupEpilogueFragment.access$200(SignupEpilogueFragment.java:103)
public class SignupEpilogueFragment extends LoginBaseFormFragment<SignupEpilogueListener>
at org.wordpress.android.ui.accounts.signup.SignupEpilogueFragment$13.onError(SignupEpilogueFragment.java:752)
endProgress();
...
(20 additional frame(s) were not displayed)
Thanks for reporting! 👍
@maxme, I did a quick investigation about this issue and it looks like the new Gravatar-related code, introduced by you in https://github.com/wordpress-mobile/WordPress-Android/pull/20590, is causing this crash in WordPress 24.7, which currently seems to have affected only a few users.
I am adding you as an assignee but feel free to assign someone else if it makes sense.
What I believe to be the root cause of the issue is that the AvatarService.upload method runs inside a coroutine in a background thread and also calls the callbacks from GravatarListener from within that background thread, but endProgress called by both callbacks needs to run on the UI thread, and the thread is not being switched anywhere.
https://github.com/wordpress-mobile/WordPress-Android/blob/9eb84303b230f36698d7b03c5552f9239b42d85e/WordPress/src/main/java/org/wordpress/android/ui/accounts/signup/SignupEpilogueFragment.java#L740-L758
A couple of quick fix suggestions I could think of are:
- Use
getActivity().runOnUiThreadin the WP-Android-side around any parts of callback code that interact with the UI (endProgress,setVisibility, etc) - Make changes in the Gravatar-SDK-Android
AvatarServiceto always call listener callbacks in the UI thread, which is usually the expected behavior in APIs than own their background execution (something like usingwithContext(Dispatchers.Main)around the code that callsonSuccessandonError).
Anyway, these are just suggestion I could come up with after doing a quick investigation, so feel free to ignore them if it doesn't make sense as well.
Thanks @thomashorta for investigating, yeah I think having onSuccess and onError running on the main Android thread is best, I'll fix it in a 0.2.1 release of gravatar.
Sentry Issue: JETPACK-ANDROID-R1X
Sentry Issue: JETPACK-ANDROID-R3V
This appears to have been resolved by #20795.