ReactNative 打的release包闪退之——undefined is not an object (evaluating 'a.View.propTypes.style')?...

ReactNative 打的release包闪退之——undefined is not an object (evaluating 'a.View.propTypes.style')?

现象描述:

使用react-native run-android 命令打的包能正常安装在模拟器上运行,一切都是那么的平静。然而,我使用gradlew assembleRelease命令打出的生产包,编译都ok,已安装到手机上(android)启动时就崩了,使用手机连上androidStudio后,看到报的日志是undefined is not an object (evaluating ‘a.View.propTypes.style’)(或者是XXX.View.propTypes.style’)

ReactNative 打的release包闪退之——undefined is not an object (evaluating 'a.View.propTypes.style')?...

代码示例:

static propTypes = {
        style: View.propTypes.style,
        title: PropTypes.string,
        titleView: PropTypes.element,
        titleLayoutStyle:View.propTypes.style,
        hide: PropTypes.bool,
        statusBar: PropTypes.shape(StatusBarShape),
        rightButton:  PropTypes.element,
        leftButton: PropTypes.element,

    }

ReactNative 打的release包闪退之——undefined is not an object (evaluating 'a.View.propTypes.style')?...

解决方案:

安装第三方库prop-types

npm install prop-types --save

 

在文件中引入PropTypes

import PropTypes from 'prop-types';

 

 

将所有

View.propTypes.XXX

 

换成

PropTypes.XXX

posted @ 2019-03-19 13:58 journeyIT 阅读(...) 评论(...) 编辑 收藏