React Native App Debug 模式工作正常,Release 模式崩溃(App Registry 和评估 'a.View.propTypes.style')

Posted

技术标签:

【中文标题】React Native App Debug 模式工作正常,Release 模式崩溃(App Registry 和评估 \'a.View.propTypes.style\')【英文标题】:React Native App Debug mode works fine, Release mode crashes (App Registry and evaluating 'a.View.propTypes.style')React Native App Debug 模式工作正常,Release 模式崩溃(App Registry 和评估 'a.View.propTypes.style') 【发布时间】:2018-05-06 20:42:14 【问题描述】:

我最近一直在实现地图框,并且我已经更新到最新版本的 react-native、gradle 等等。该应用程序在调试模式下运行得非常好,但是一旦我在发布模式下运行它,它就会立即崩溃,根本没有任何警告屏幕。我正在使用新的 propTypes,等等。

请查看输出日志

好的,我很抱歉,虽然上述内容在调试模式下工作,但应用程序现在在构建版本时崩溃,我很困惑。

我正在尝试构建一个版本,尽管在调试模式下工作正常,但立即崩溃:

11-23 00:48:14.499: E/SDAgentPackageStateReceiver(6040): Not going to handle 'com.goclustr.clustr'!
11-23 00:48:14.704: E/CS/CscParser(20341): mps_code.dat does not exist
11-23 00:48:14.720: E/CS/CscParser(20341): mps_code.dat does not exist
11-23 00:48:14.735: E/CS/CscParser(20341): mps_code.dat does not exist
11-23 00:48:14.884: E/Launcher.Model(1564): onPackageAdded :com.goclustr.clustr
11-23 00:48:14.906: E/ApplicationPackageManager(1564): checkSettingsForIconTray value : 0
11-23 00:48:14.907: E/ApplicationPackageManager(1564): checkSettingsForIconTray value : 0
11-23 00:48:15.589: E/ReflectField(20468): Incorrect type : Fallback exception
11-23 00:48:15.589: E/ReflectField(20468): Incorrect type : Fallback exception
11-23 00:48:15.778: E/SemAffinityControl(20435): SemAffinityControl: registerfunction enter
11-23 00:48:16.281: E/SensorService(6040): getSensorList a sensor (MAX86902) without holding its required permission: com.samsung.permission.SSENSOR
11-23 00:48:16.281: E/SensorService(6040): getSensorList a sensor (HRM Ambient Light Canceling) without holding its required permission: com.samsung.permission.HRM_EXT
11-23 00:48:16.281: E/SensorService(6040): getSensorList a sensor (HRM Proximity detecting) without holding its required permission: com.samsung.permission.HRM_EXT
11-23 00:48:16.281: E/SensorService(6040): getSensorList a sensor (HRM Sensor) without holding its required permission: com.samsung.permission.SSENSOR
11-23 00:48:16.281: E/SensorService(6040): getSensorList a sensor (Sensor Diagnostic Monitor) without holding its required permission: com.samsung.permission.SSENSOR
11-23 00:48:16.297: E/Finsky(311): [1] com.google.android.finsky.wear.bk.a(3): onConnectionFailed: ConnectionResultstatusCode=API_UNAVAILABLE, resolution=null, message=null
11-23 00:48:16.633: E/AndroidRuntime(20526): Process: com.goclustr.clustr, PID: 20526
11-23 00:48:16.633: E/AndroidRuntime(20526): com.facebook.react.common.javascriptException: undefined is not an object (evaluating 'a.View.propTypes.style'), stack:
11-23 00:48:16.633: E/AndroidRuntime(20526): global code@841:9
11-23 00:48:16.633: E/AndroidRuntime(20526):    at com.facebook.react.modules.core.ExceptionsManagerModule.showOrThrowError(ExceptionsManagerModule.java:56)
11-23 00:48:16.633: E/AndroidRuntime(20526):    at com.facebook.react.modules.core.ExceptionsManagerModule.reportFatalException(ExceptionsManagerModule.java:40)
11-23 00:48:16.633: E/AndroidRuntime(20526):    at com.facebook.react.bridge.JavaMethodWrapper.invoke(JavaMethodWrapper.java:374)
11-23 00:48:16.633: E/AndroidRuntime(20526):    at com.facebook.react.bridge.JavaModuleWrapper.invoke(JavaModuleWrapper.java:162)
11-23 00:48:16.633: E/AndroidRuntime(20526):    at com.facebook.react.bridge.queue.NativeRunnable.run(Native Method)
11-23 00:48:16.633: E/AndroidRuntime(20526):    at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:31)
11-23 00:48:16.633: E/AndroidRuntime(20526):    at com.facebook.react.bridge.queue.MessageQueueThreadImpl$3.run(MessageQueueThreadImpl.java:194)
11-23 00:48:16.850: E/ApplicationPackageManager(6833): checkSettingsForIconTray value : 0
11-23 00:48:16.850: E/ApplicationPackageManager(6833): checkSettingsForIconTray value : 0
11-23 00:48:16.865: E/ApplicationPackageManager(6833): checkSettingsForIconTray value : 0
11-23 00:48:17.259: E/ReactNativeJS(20526): Module AppRegistry is not a registered callable module (calling unmountApplicationComponentAtRootTag)
11-23 00:48:18.615: E/SMTCodec(20807): Fail to load libsmtcodec.so
11-23 00:48:18.616: E/SMTCodec(20807): [VoiceCodec] Can use only PCM mode. 
11-23 00:48:19.302: E/HealthDataStore(20878): disconnectService: Context instance is invalid
11-23 00:48:20.297: E/HealthDataStore(20903): disconnectService: Context instance is invalid
11-23 00:48:20.588: E/com.strava.util.Benchmark(20998): "com.strava.StravaApplication.total" took 285 ms, but expected 60-175 ms
11-23 00:48:21.328: E/ActivityThread(20789): Failed to find provider info for com.samsung.accessory.saproviders.sasvoice.util.SASVoiceNativeAppProvider
11-23 00:48:21.486: E/HealthDataStore(20878): disconnectService: Context instance is invalid
11-23 00:48:27.157: E/svoiceapi(20789): in pds_open function, Caught RCF::Exception: Unable to establish network connection.
11-23 00:48:27.158: E/svoiceapi(20789): KEY : rampcode, VALUE : dash
11-23 00:48:27.158: E/svoiceapi(20789): KEY : reason, VALUE : Unable to establish network connection
11-23 00:48:45.574: E/CS/CscParser(21190): mps_code.dat does not exist
11-23 00:48:45.588: E/CS/CscParser(21190): mps_code.dat does not exist
11-23 00:48:45.602: E/CS/CscParser(21190): mps_code.dat does not exist
11-23 00:48:46.291: E/SensorService(6040): getSensorList a sensor (MAX86902) without holding its required permission: com.samsung.permission.SSENSOR
11-23 00:48:46.291: E/SensorService(6040): getSensorList a sensor (HRM Ambient Light Canceling) without holding its required permission: com.samsung.permission.HRM_EXT

如您所见,有一个错误

11-23 00:48:17.259: E/ReactNativeJS(20526): Module AppRegistry is not a registered callable module (calling unmountApplicationComponentAtRootTag)

com.facebook.react.common.JavascriptException: undefined is not an object (evaluating 'a.View.propTypes.style'), stack:

在调试模式下都不是问题

非常感谢!

【问题讨论】:

我认为您必须更改代码中的 View.propTypes.style,因为它已被弃用,请将其更改为 ViewPropTypes.style。还要从“react-native”导入 ViewPropTypes ; Docs 在这里 facebook.github.io/react-native/docs/viewproptypes.html 但现在找不到,我想他们会对其进行一些更改。 您的一些节点模块使用 View.propTypes.style 代替 ViewPropTypes.style。从您发布的日志中无法判断是哪一个。尝试将您的模块更新到最新版本。有时即使更新节点模块也无济于事,因为许多 npm 库仍然没有更新它们的代码,但大多数“流行”的库都更新了。 谢谢@zarcode 我已经添加了一个答案,但对我来说,它似乎是react-native-router-flux 版本0.38.0,但是当升级到4.0.0-beta.24 时问题得到了解决。运行 jscodeshift -t react-codemod/transforms/React-PropTypes-to-prop-types.js myapp/ 也有帮助。 很好,我喜欢你的解决方案。我已经派生了具有旧代码的库,直到他们更新它为止。 谢谢@zarcode 很高兴我能帮上忙,起初这很令人沮丧,但运行发布版本时的 Android 设备监视器似乎提供了一些有用的提示以及其他一切 【参考方案1】:

使用react-codemon,在您的项目目录上运行

jscodeshift -t react-codemod/transforms/React-PropTypes-to-prop-types.js myapp/

这将解决更新源代码和任何节点模块的 proptypes。

重新安装节点模块似乎需要再次运行该命令。

请按照https://github.com/reactjs/react-codemod 的说明进行操作,但基本上是在您安装了jscodeshift 之后,并且您已经下载了上述react-codemod 文件以获取各种命令,例如将React.propTypes 转换为PropTypes 等。

myapp/这里对应我整个应用项目目录所以整个react-native项目。

其次,考虑您正在使用的项目依赖项。例如,在我的情况下,我在版本 0.38.0 中使用 react-native-router-flux,该应用程序将在调试模式下工作,但在发布时崩溃。我尝试升级到4.0.0-beta.24 的最新测试版,问题已解决。

【讨论】:

以上是关于React Native App Debug 模式工作正常,Release 模式崩溃(App Registry 和评估 'a.View.propTypes.style')的主要内容,如果未能解决你的问题,请参考以下文章

没有这样的文件或目录,在 React-Native 中打开 'app\build\intermediates\merged_manifests\debug\AndroidManifest.xml'

react native ios端debug模式下图片无法加载问题记录

运行`detox build -c android.emu.debug`任务时出错:app:compileDebugJavaWithJavac FAILED in react native

react-native android 运行命令

react-native 日常报错

react-native 未在 Android 更新后运行