React-Native:在 Android 10 和 9(API 28 和 29)dalvik.system.BaseDexClassLoader.findClass 上崩溃

Posted

技术标签:

【中文标题】React-Native:在 Android 10 和 9(API 28 和 29)dalvik.system.BaseDexClassLoader.findClass 上崩溃【英文标题】:React-Native: Crash on Android 10 and 9 (API 28 and 29) dalvik.system.BaseDexClassLoader.findClass 【发布时间】:2021-02-21 17:46:05 【问题描述】:

所以,最近我将我的 react-native 应用程序从使用框架的 0.59 版本更新为使用 0.63。事情进展顺利,直到我注意到在 Google Play 上上传新的 .AAB 文件后,我的一部分用户(约 10%)开始收到此错误“dalvik.system.BaseDexClassLoader.findClass”。

经过调查,我发现它只发生在 API 级别为 28 或 29 的部分(不是全部)设备上,如下面的仪表板所示:

Google Play Error Report

这是堆栈跟踪:

java.lang.RuntimeException: 
  at android.app.ActivityThread.handleCreateService (ActivityThread.java:4268)
  at android.app.ActivityThread.access$1500 (ActivityThread.java:270)
  at android.app.ActivityThread$H.handleMessage (ActivityThread.java:2067)
  at android.os.Handler.dispatchMessage (Handler.java:107)
  at android.os.Looper.loop (Looper.java:237)
  at android.app.ActivityThread.main (ActivityThread.java:7948)
  at java.lang.reflect.Method.invoke (Native Method)
  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:493)
  at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1075)
Caused by: java.lang.ClassNotFoundException: 
  at dalvik.system.BaseDexClassLoader.findClass (BaseDexClassLoader.java:196)
  at java.lang.ClassLoader.loadClass (ClassLoader.java:379)
  at java.lang.ClassLoader.loadClass (ClassLoader.java:312)
  at android.app.AppComponentFactory.instantiateService (AppComponentFactory.java:129)
  at androidx.core.app.CoreComponentFactory.instantiateService (CoreComponentFactory.java:75)
  at android.app.ActivityThread.handleCreateService (ActivityThread.java:4263)

我已经在互联网上搜索了解决方案,并尝试了其中的一些,但都没有修复它。有人说和MultiDex支持有关,但我早就启用了:

defaultConfig 
    multiDexEnabled true

还有:

dependencies 
    def multidex_version = "2.0.1"
    implementation 'androidx.multidex:multidex:2.0.1'

如果有人能阐明问题所在,我将不胜感激。这是我的 package.json:

"dependencies": 
        "@react-native-community/async-storage": "1.12.0",
        "@react-native-community/datetimepicker": "3.0.2",
        "@react-native-community/masked-view": "^0.1.10",
        "@react-native-community/netinfo": "5.9.7",
        "@react-native-community/picker": "1.7.1",
        "@react-native-community/push-notification-ios": "^1.5.0",
        "EventEmitter": "1.0.0",
        "aws-sdk": "2.757.0",
        "axios": "0.18.0",
        "blueimp-md5": "^2.10.0",
        "firebase": "6.2.4",
        "firebase-key": "2.0.2",
        "jwt-decode": "^2.2.0",
        "lodash": "4.17.5",
        "mobx": "3.1.10",
        "mobx-react": "4.2.1",
        "mobx-remotedev": "0.2.8",
        "mobx-utils": "2.0.2",
        "moment": "^2.19.0",
        "native-base": "2.13.14",
        "ramda": "0.24.1",
        "react": "16.13.1",
        "react-native": "0.63.3",
        "react-native-action-button": "^2.8.5",
        "react-native-build-config": "0.3.2",
        "react-native-camera": "3.40.0",
        "react-native-code-push": "6.3.0",
        "react-native-device-info": "6.0.2",
        "react-native-document-picker": "2.3.0",
        "react-native-fbsdk": "2.0.0",
        "react-native-file-viewer": "2.1.4",
        "react-native-gesture-handler": "^1.8.0",
        "react-native-gifted-chat": "^0.16.3",
        "react-native-hyperlink": "0.0.12",
        "react-native-masked-text": "^1.5.3",
        "react-native-mime-types": "^2.3.0",
        "react-native-push-notification": "5.1.1",
        "react-native-reanimated": "^1.13.0",
        "react-native-safe-area-context": "^3.1.8",
        "react-native-screens": "^2.11.0",
        "react-native-tab-view": "^2.15.1",
        "react-native-vector-icons": "7.1.0",
        "react-native-webview": "10.9.0",
        "react-navigation": "4.4.1",
        "react-navigation-drawer": "2.5.1",
        "react-navigation-stack": "2.8.3",
        "react-navigation-tabs": "2.9.1",
        "rn-fetch-blob": "0.12.0",
        "uuid": "3.1.0",
        "validator": "^9.4.1"
    ,
    "devDependencies": 
        "@babel/core": "^7.8.4",
        "@babel/plugin-proposal-decorators": "7.4.4",
        "@babel/preset-flow": "7.0.0",
        "@babel/runtime": "^7.8.4",
        "@react-native-community/eslint-config": "^1.1.0",
        "@types/prop-types": "15.7.1",
        "babel-eslint": "10.0.2",
        "babel-jest": "^25.1.0",
        "babel-preset-react-native": "4.0.1",
        "eslint": "^6.5.1",
        "eslint-config-airbnb": "17.1.0",
        "eslint-import-resolver-reactnative": "^1.0.2",
        "eslint-plugin-flowtype": "3.11.1",
        "eslint-plugin-import": "2.17.3",
        "eslint-plugin-jsx-a11y": "6.2.1",
        "eslint-plugin-react": "7.14.1",
        "flow-bin": "^0.65.0",
        "grpc": "1.21.1",
        "jest": "^25.1.0",
        "jetifier": "^1.6.6",
        "metro-react-native-babel-preset": "^0.59.0",
        "react-test-renderer": "16.13.1"
    

谢谢!

【问题讨论】:

【参考方案1】:

我遇到了同样的错误,在我的情况下,这是一个类缺失。

如果你有机会,得到一个有错误的设备,当发送反馈模式弹出时,点击预览按钮,向下滚动,然后选择“堆栈跟踪”。

我可以找出缺少的课程。

【讨论】:

【参考方案2】:

我们通过更新我们的 zo0r/react-native-push-notification 依赖项并从使用已弃用的 GCM 通知格式(理论上仍支持 Amazon SNS,但新版本的 zo0r/react-native-push-notification 不支持)迁移来修复了此错误转为 FCM 格式。

进行这些更改后,错误不再出现在 Google Play 控制台上。

【讨论】:

以上是关于React-Native:在 Android 10 和 9(API 28 和 29)dalvik.system.BaseDexClassLoader.findClass 上崩溃的主要内容,如果未能解决你的问题,请参考以下文章

React-native google auth android DEVELOPER_ERROR 代码 10

React-native 占位符仅在 Android 上部分可见

react-native android fetch json停止工作

如何在 Android 上减小 expo/react-native 应用程序的大小

React-Native SectionList 滚动到Android上的项目

POST 方法在 react-native 应用程序(Android)中不起作用(Fetch 或 Axios)