【react-native-picker】报错解决方案
扫描二维码
随时随地手机看文章
在安装react-native-picker过程中,react-native link报错,且没有任何错误日志说明错误原因,导致运行项目时出现undefined is not an object (evaluating 'Picker._init')的错误。
网上找到了两个解决方案:
https://github.com/beefe/react-native-picker/issues/289
https://github.com/beefe/react-native-picker/issues/294
综合整理后,解决方案如下:
1.文件./android/settings.gradle中末尾添加:
include ':react-native-picker' project(':react-native-picker').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-picker/android')
2.文件./android/app/build.gradle的dependencies内添加(注意其他行有逗号",",最后一行没逗号):
... dependencies { ... compile project(':react-native-picker') } ...
3.文件./android/app/src/main/java/com/xxx/xxx/MainApplication.java中添加:
import com.beefe.picker.PickerViewPackage; ... @Override protected ListgetPackages() { return Arrays.asList( new MainReactPackage(), ... new PickerViewPackage() ); } ...
4.重新运行项目就OK了。