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

问题描述

因此,最近我已将我的react-native应用程序从使用框架的0.59版本更新为使用0.63。一切进展顺利,直到我注意到在将新的.AAB文件上传到Google Play后,我的用户中的一部分(大约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"
    }

谢谢!

解决方法

我有同样的错误,就我而言,这是一个缺少的类。

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

我可以找出缺少的课程。

,

我们设法通过更新zo0r/react-native-push-notification依赖项并使用不建议使用的GCM通知格式进行迁移来解决此错误(Amazon SNS在理论上仍支持该格式,但新版本的zo0r / react-native-push-notification没有) t)转换为FCM格式。

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