将targetSdkVersion升级到31 React Native后,应用程序至少5000 ms没有响应



将目标sdk版本升级到31后,我发现应用程序在play store上经常崩溃。在测试时没有收到相同的错误。只有三星的安卓13设备才会出现崩溃。以下是在Sentry上收到的两个错误日志。

io.sentry.android.core.ApplicationNotResponding: Application Not Responding for at least 5000 ms.
at dalvik.system.VMRuntime.notifyNativeAllocationsInternal(VMRuntime.java)
at dalvik.system.VMRuntime.notifyNativeAllocation(VMRuntime.java:701)
at libcore.util.NativeAllocationRegistry.registerNativeAllocation(NativeAllocationRegistry.java:316)
at libcore.util.NativeAllocationRegistry.registerNativeAllocation(NativeAllocationRegistry.java:264)
at android.graphics.text.LineBreaker.<init>(LineBreaker.java:462)
at android.graphics.text.LineBreaker.<init>
at android.graphics.text.LineBreaker$Builder.build(LineBreaker.java:239)
at android.text.StaticLayout.generate(StaticLayout.java:681)
at android.text.DynamicLayout.reflow(DynamicLayout.java:612)
at android.text.DynamicLayout$ChangeWatcher.reflow(DynamicLayout.java:1091)
at android.text.DynamicLayout$ChangeWatcher.onSpanChanged(DynamicLayout.java:1126)
at android.text.SpannableStringBuilder.sendSpanChanged(SpannableStringBuilder.java:1321)
at android.text.SpannableStringBuilder.sendToSpanWatchers(SpannableStringBuilder.java:665)
at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:594)
at android.text.SpannableStringBuilder.delete(SpannableStringBuilder.java:232)
at android.text.SpannableStringBuilder.delete(SpannableStringBuilder.java:39)
at android.text.method.BaseKeyListener.backspaceOrForwardDelete(BaseKeyListener.java:376)
at android.text.method.BaseKeyListener.backspace(BaseKeyListener.java:71)
at android.text.method.BaseKeyListener.onKeyDown(BaseKeyListener.java:485)
at android.text.method.QwertyKeyListener.onKeyDown(QwertyKeyListener.java:362)
at com.facebook.react.views.textinput.c$b.onKeyDown(ReactEditText.java:1)
at android.widget.TextView.doKeyDown(TextView.java:9503)
at android.widget.TextView.onKeyDown(TextView.java:9275)
at android.view.KeyEvent.dispatch(KeyEvent.java:3501)
at android.view.View.dispatchKeyEvent(View.java:15384)
at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1978)
at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1978)
at android.widget.ScrollView.dispatchKeyEvent(ScrollView.java:738)
at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1978)
at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1978)
at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1978)
at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1978)
at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1978)
at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1978)
at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1978)
at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1978)
at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1978)
at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1978)
at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1978)
at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1978)
at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1978)
at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1978)
at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1978)
at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1978)
at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1978)
at com.facebook.react.y.dispatchKeyEvent(ReactRootView.java:4)
at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1978)
at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1978)
at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1978)
at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1978)
at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1978)
at com.android.internal.policy.DecorView.superDispatchKeyEvent(DecorView.java:1091)
at com.android.internal.policy.PhoneWindow.superDispatchKeyEvent(PhoneWindow.java:1958)
at android.app.Activity.dispatchKeyEvent(Activity.java:4329)
at androidx.core.app.f.superDispatchKeyEvent(ComponentActivity.java:1)
at androidx.core.view.g.e(KeyEventDispatcher.java:2)
at androidx.core.app.f.dispatchKeyEvent(ComponentActivity.java:3)
at androidx.appcompat.app.d.dispatchKeyEvent(AppCompatActivity.java:4)
at j.i.dispatchKeyEvent(WindowCallbackWrapper.java:1)
at androidx.appcompat.app.g$o.dispatchKeyEvent(AppCompatDelegateImpl.java:2)
at com.android.internal.policy.DecorView.dispatchKeyEvent(DecorView.java:915)
at android.view.ViewRootImpl$ViewPostImeInputStage.processKeyEvent(ViewRootImpl.java:7844)
at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:7652)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:7001)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:7058)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:7024)
at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:7222)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:7032)
at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:7279)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:7005)
at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:7058)
at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:7024)
at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:7032)
at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:7005)
at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:10568)
at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:10456)
at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:10412)
at android.view.ViewRootImpl$ViewRootHandler.handleMessageImpl(ViewRootImpl.java:6616)
at android.view.ViewRootImpl$ViewRootHandler.handleMessage(ViewRootImpl.java:6491)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loopOnce(Looper.java:226)
at android.os.Looper.loop(Looper.java:313)
at android.app.ActivityThread.main(ActivityThread.java:8741)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:571)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1067)

第二个

io.sentry.android.core.ApplicationNotResponding: Application Not Responding for at least 5000 ms.
at android.text.SpannableStringInternal.getSpanFlags(SpannableStringInternal.java:331)
at android.text.SpannableString.getSpanFlags(SpannableString.java:24)
at android.text.SpannableStringInternal.getSpans(SpannableStringInternal.java:389)
at android.text.SpannableString.getSpans(SpannableString.java:24)
at android.text.SpannableStringBuilder.change(SpannableStringBuilder.java:434)
at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:563)
at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:521)
at android.text.SpannableStringBuilder.replace(SpannableStringBuilder.java:39)
at android.view.inputmethod.BaseInputConnection.replaceText(BaseInputConnection.java:945)
at android.view.inputmethod.BaseInputConnection.commitText(BaseInputConnection.java:219)
at com.android.internal.inputmethod.EditableInputConnection.commitText(EditableInputConnection.java:201)
at com.android.internal.inputmethod.RemoteInputConnectionImpl.lambda$commitText$16$com-android-internal-inputmethod-RemoteInputConnectionImpl(RemoteInputConnectionImpl.java:569)
at com.android.internal.inputmethod.RemoteInputConnectionImpl$$ExternalSyntheticLambda34.run
at android.os.Handler.handleCallback(Handler.java:942)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loopOnce(Looper.java:226)
at android.os.Looper.loop(Looper.java:313)
at android.app.ActivityThread.main(ActivityThread.java:8741)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:571)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1067)

对于第二个问题,我已经尝试关闭三星设备的文本输入自动纠错功能。通过添加androidx.work:work-runtime:2.7.1.

所以在阅读了很多github问题之后,下面的代码是对ANR问题的临时修复。为这些keyboardType, autoCorrect, spellCheck添加了false

<TextInput
value={this.state.msg}
placeholder="Type something here..."
placeholderTextColor = {Colors.placeholderColor}
multiline={true}
onChangeText={async val => {
await this.setState({msg: val});
}}
keyboardType={DeviceInfo?.getBrand()?.toLowerCase() === 'samsung' ? 'visible-password' : 'default'}
numberOfLines={ DeviceInfo?.getBrand()?.toLowerCase() === 'samsung' ? (this.state.msg.length > 50 && this.state.msg !== '' ? 3 : 1) : 1}
textAlignVertical='top'
autoCorrect={DeviceInfo?.getBrand()?.toLowerCase() !== 'samsung'}
// returnKeyType={DeviceInfo?.getBrand()?.toLowerCase() !== 'samsung' ? 'default' : 'none'}
spellCheck={DeviceInfo?.getBrand()?.toLowerCase() !== 'samsung'}
style={styles.chatInputField}
/>

相关内容

  • 没有找到相关文章

最新更新