在运行 Android 10 的小米设备上,EditText TextInput 中的电子邮件崩溃

Posted

技术标签:

【中文标题】在运行 Android 10 的小米设备上,EditText TextInput 中的电子邮件崩溃【英文标题】:Crash with email in EditText TextInput on Xiaomi devices running android 10 【发布时间】:2020-05-30 01:52:19 【问题描述】:

最近我在 google play 控制台中遇到了崩溃。

java.lang.NullPointerException:  
  at android.widget.Editor$SelectionModifierCursorController.access$300 (Editor.java:6696) 
  at android.widget.Editor.getEmailPopupWindow (Editor.java:1469) 
  at android.widget.Editor.showEmailPopupWindow (Editor.java:1477) 
  at android.widget.Editor.handleEmailPopup (Editor.java:1456) 
  at android.widget.Editor.updateCursorPosition (Editor.java:2099) 
  at android.widget.TextView.getUpdatedHighlightPath (TextView.java:7813) 
  at android.widget.TextView.onDraw (TextView.java:7998) 
  at android.view.View.draw (View.java:21472) 
  at android.view.View.updateDisplayListIfDirty (View.java:20349) 
  at android.view.View.draw (View.java:21204) 
  at android.view.ViewGroup.drawChild (ViewGroup.java:4412) 
  at android.view.ViewGroup.dispatchDraw (ViewGroup.java:4171) 
  at android.view.View.updateDisplayListIfDirty (View.java:20340) 
  at android.view.View.draw (View.java:21204) 
  at android.view.ViewGroup.drawChild (ViewGroup.java:4412) 
  at android.view.ViewGroup.dispatchDraw (ViewGroup.java:4171) 
  at android.view.View.updateDisplayListIfDirty (View.java:20340) 
  at android.view.View.draw (View.java:21204) 
  at android.view.ViewGroup.drawChild (ViewGroup.java:4412) 
  at androidx.recyclerview.widget.RecyclerView.drawChild (RecyclerView.java:4820) 
  at android.view.ViewGroup.dispatchDraw (ViewGroup.java:4171) 
  at android.view.View.updateDisplayListIfDirty (View.java:20340) 
  at android.view.View.draw (View.java:21204) 
  at android.view.ViewGroup.drawChild (ViewGroup.java:4412) 
  at android.view.ViewGroup.dispatchDraw (ViewGroup.java:4171) 
  at android.view.View.draw (View.java:21475) 
  at android.view.View.updateDisplayListIfDirty (View.java:20349) 
  at android.view.View.draw (View.java:21204) 
  at android.view.ViewGroup.drawChild (ViewGroup.java:4412) 
  at android.view.ViewGroup.dispatchDraw (ViewGroup.java:4171) 
  at android.view.View.draw (View.java:21475) 
  at android.view.View.updateDisplayListIfDirty (View.java:20349) 
  at android.view.View.draw (View.java:21204) 
  at android.view.ViewGroup.drawChild (ViewGroup.java:4412) 
  at android.view.ViewGroup.dispatchDraw (ViewGroup.java:4171) 
  at androidx.constraintlayout.widget.ConstraintLayout.dispatchDraw (ConstraintLayout.java:2023) 
  at android.view.View.updateDisplayListIfDirty (View.java:20340) 
  at android.view.View.draw (View.java:21204) 
  at android.view.ViewGroup.drawChild (ViewGroup.java:4412) 
  at androidx.coordinatorlayout.widget.CoordinatorLayout.drawChild (CoordinatorLayout.java:1246) 
  at android.view.ViewGroup.dispatchDraw (ViewGroup.java:4171) 
  at android.view.View.updateDisplayListIfDirty (View.java:20340) 
  at android.view.View.draw (View.java:21204) 
  at android.view.ViewGroup.drawChild (ViewGroup.java:4412) 
  at android.view.ViewGroup.dispatchDraw (ViewGroup.java:4171) 
  at android.view.View.draw (View.java:21475) 
  at android.view.View.updateDisplayListIfDirty (View.java:20349) 
  at android.view.View.draw (View.java:21204) 
  at android.view.ViewGroup.drawChild (ViewGroup.java:4412) 
  at android.view.ViewGroup.dispatchDraw (ViewGroup.java:4171) 
  at android.view.View.updateDisplayListIfDirty (View.java:20340) 
  at android.view.View.draw (View.java:21204) 
  at android.view.ViewGroup.drawChild (ViewGroup.java:4412) 
  at android.view.ViewGroup.dispatchDraw (ViewGroup.java:4171) 
  at android.view.View.updateDisplayListIfDirty (View.java:20340) 
  at android.view.View.draw (View.java:21204) 
  at android.view.ViewGroup.drawChild (ViewGroup.java:4412) 
  at android.view.ViewGroup.dispatchDraw (ViewGroup.java:4171) 
  at android.view.View.updateDisplayListIfDirty (View.java:20340) 
  at android.view.View.draw (View.java:21204) 
  at android.view.ViewGroup.drawChild (ViewGroup.java:4412) 
  at android.view.ViewGroup.dispatchDraw (ViewGroup.java:4171) 
  at android.view.View.updateDisplayListIfDirty (View.java:20340) 
  at android.view.View.draw (View.java:21204) 
  at android.view.ViewGroup.drawChild (ViewGroup.java:4412) 
  at android.view.ViewGroup.dispatchDraw (ViewGroup.java:4171) 
  at android.view.View.draw (View.java:21475) 
  at com.android.internal.policy.DecorView.draw (DecorView.java:830) 
  at android.view.View.updateDisplayListIfDirty (View.java:20349) 
  at android.view.ThreadedRenderer.updateViewTreeDisplayList (ThreadedRenderer.java:575) 
  at android.view.ThreadedRenderer.updateRootDisplayList (ThreadedRenderer.java:581) 
  at android.view.ThreadedRenderer.draw (ThreadedRenderer.java:654) 
  at android.view.ViewRootImpl.draw (ViewRootImpl.java:3687) 
  at android.view.ViewRootImpl.performDraw (ViewRootImpl.java:3482) 
  at android.view.ViewRootImpl.performTraversals (ViewRootImpl.java:2819) 
  at android.view.ViewRootImpl.doTraversal (ViewRootImpl.java:1782) 
  at android.view.ViewRootImpl$TraversalRunnable.run (ViewRootImpl.java:7785) 
  at android.view.Choreographer$CallbackRecord.run (Choreographer.java:1031) 
  at android.view.Choreographer.doCallbacks (Choreographer.java:854) 
  at android.view.Choreographer.doFrame (Choreographer.java:789) 
  at android.view.Choreographer$FrameDisplayEventReceiver.run (Choreographer.java:1016) 
  at android.os.Handler.handleCallback (Handler.java:883) 
  at android.os.Handler.dispatchMessage (Handler.java:100) 
  at android.os.Looper.loop (Looper.java:224) 
  at android.app.ActivityThread.main (ActivityThread.java:7520) 
  at java.lang.reflect.Method.invoke (Method.java) 
  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:539) 
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:950)

设备:Redmi K20 Pro

安卓版本:10

在android sources找不到这部分代码(嗯,好像是小米改装的)

我在 React-Native 社区找到了same issue。

关于如何解决它的任何想法?

UPD:我在完全原生的应用程序上遇到了这个崩溃,没有任何跨平台框架。

【问题讨论】:

这里也一样!到目前为止还没有解决方案,Facebook 关闭了这个问题。 也许这就是他们回答这个问题的地方。 xiaomi.eu/community/threads/… 我也有同样的问题。我还没有找到解决方案... 【参考方案1】:

我为原生 android 开发者找到了一个解决方案。我相信你必须在你的 editText 中使用 inputType 作为 'textEmailAddress',只需将其更改为:

android:inputType="textNoSuggestions|textEmailAddress"

【讨论】:

【参考方案2】:

我昨天也遇到了同样的问题。因此,我花了一些时间才发现,如果我在电子邮件输入字段中输入 .(点)然后清除它,之后输入电子邮件不会再使应用程序崩溃。因此,这是另一种解决方法,它不包括插入符号隐藏,并且仍在 Redmi 9 上为我工作。

const [email, setEmail] = useState(".");

useEffect(() => 
  setTimeout(() => 
    setEmail("");
  , 1);
, []);

【讨论】:

【参考方案3】:

这个crash是操作系统造成的,实际上是小米定制了安卓,10版本的修改导致了这个crash。有一个解决方案,通过true 值传递caretHidden 标志,这个问题就会消失:

<TextInput
  caretHidden=true
  ...

我们可以写得更好一点:

<TextInput
  caretHidden
  ...

【讨论】:

以上是关于在运行 Android 10 的小米设备上,EditText TextInput 中的电子邮件崩溃的主要内容,如果未能解决你的问题,请参考以下文章

Sqlite Table 不在小米 Note 7s 上创建,而是在 Android Studio 中的其他手机和虚拟设备上创建

Boot BroadcastReceiver 在小米设备上不起作用

Sqlite表在小米Note 7s上不创建,但在其他手机和Android Studio中的虚拟设备上创建。

Ubuntu18.04下QT开发Android无法连接设备问题解决

Ubuntu18.04下QT开发Android无法连接设备问题解决

Android实例-红外线操作(XE10.2+小米5)