工作的时候跑一个别人的RN项目遇到的一些坑,及汇总的解决方法
react-native 遇到的一些问题
-
问题1
error Failed to build iOS project. We ran "xcodebuild" command but it exited with error code 65. To debug build logs further, consider building your app with Xcode.app, by opening DvaStarter.xcworkspace. Run CLI with --verbose flag for more details.
方法1:
- 删除
/ios
目录下的build,然后替换react-native版本为0.59.5,重新react-native run-ios
方法2:
- open the
/ios
folder in x-code - navigate File -> Project Setting
- s -> Build System -> change (Shared workspace settings and Per-User workspace settings): Build System -> Legacy Build System
- 重复方法1
-
问题2
Invalid `Podfile` file: syntax error, unexpected tIDENTIFIER, expecting end..
方法:原因是podfile 格式有问题,建议重装一下podfile
a. 删除podfile 和podfile.lock
b. cd ios,在ios目录下pod init
c .DvaStarter-tvOSTests部分会出现两次,删除target ‘DvaStarter’ do{…}end中间的DvaStarter-tvOSTests部分
target 'DvaStarter-tvOSTests' do
inherit! :search_paths
# Pods for testing
end
d. pod install 等待安装完成
-
问题3 Operation not permitted
error: open /Users/aiyouwei/Documents/company/donghuan/senseware/gzywApp/node_modules/react-native-device-info/ios/RNDeviceInfo/RNDeviceInfo.h: Operation not permitted
查看系统安全中的文件权限,为xcode打开Full Disk Access权限
-
问题4
Build system information error: Multiple commands produce '/Users/aiyouwei/Library/Developer/Xcode/DerivedData/DvaStarter-fhgjkwwflwvxhlfbaoyrkswazhfr/Build/Products/Debug-iphonesimulator/DvaStarter.app/Zocial.ttf': 1) Target 'DvaStarter' (project 'DvaStarter') has copy command from '/Users/aiyouwei/Documents/company/donghuan/senseware/gzywApp/node_modules/native-base/Fonts/Zocial.ttf' to '/Users/aiyouwei/Library/Developer/Xcode/DerivedData/DvaStarter-fhgjkwwflwvxhlfbaoyrkswazhfr/Build/Products/Debug-iphonesimulator/DvaStarter.app/Zocial.ttf' 2) Target 'DvaStarter' (project 'DvaStarter') has copy command from '/Users/aiyouwei/Documents/company/donghuan/senseware/gzywApp/node_modules/react-native-vector-icons/Fonts/Zocial.ttf' to '/Users/aiyouwei/Library/Developer/Xcode/DerivedData/DvaStarter-fhgjkwwflwvxhlfbaoyrkswazhfr/Build/Products/Debug-iphonesimulator/DvaStarter.app/Zocial.ttf'
-
问题5
podfile 格式错误
Invalid `Podfile` file: [!] Specifying multiple `post_install` hooks is unsupported
解决方法: 将post_install 的内容整体移动到global的部分,即放到所有target的外面
参考:https://github.com/CocoaPods/CocoaPods/issues/6172
-
问题6
构建失败,原因是podfile中一些东西没装
The following build commands failed: CompileC /Users/aiyouwei/Library/Developer/Xcode/DerivedData/DvaStarter-fhgjkwwflwvxhlfbaoyrkswazhfr/Build/Intermediates.noindex/Pods.build/Debug-iphonesimulator/Flipper.build/Objects-normal/x86_64/FlipperRSocketResponder.o /Users/aiyouwei/Documents/company/donghuan/senseware/gzywApp/ios/Pods/Flipper/xplat/Flipper/FlipperRSocketResponder.cpp normal x86_64 c++ com.apple.compilers.llvm.clang.1_0.compiler
解决1: 在podfile 中,项目target下面加入use_flipper!({‘Flipper’ => ‘0.58.0’}),并重新pod install,之后再次运行react-native run-ios
解决2: 如果还是不行 ,参考https://fbflipper.com/docs/getting-started/react-native-ios/ 自定义flipper_pods、flipper_post_install函数,手机flipperkit_version到0.74.0版本
-
问题7
极光推送问题
use of undeclared identifier 'kjpfdidreceiveremotenotification'
修改package.json,卸载jpush-react-native,并重装2.2.13版本,然后pod install ,之后再次运行react-native run-ios
-
问题8
Ld /Users/aiyouwei/Library/Developer/Xcode/DerivedData/DvaStarter-fhgjkwwflwvxhlfbaoyrkswazhfr/Build/Products/Debug-iphonesimulator/DvaStarter.app/DvaStarter normal
参考https://github.com/onfido/react-native-sdk/issues/15 smohamedjavid 的comment
- Open your project in Xcode (open
YourProjectName.xcodeproj
) - Select from Menu - File > New > File (⌘N) > Swift File > Next >
Onfido.swift
(Feel free to choose your file name) >Don't create headers
. - Clean your build folder (From Menu - Product > Clean Build Folder (⇧⌘K))
- Run your project now
- Open your project in Xcode (open
-
问题9
react-native No bundle URL present
解决办法:#1.start react-native start #2.run react-native run-ios
-
问题10
Pods/React/Libraries/react-native/react-native.js: React could not be found within the project or in these directories:node_modules
解决办法: 删除ios/pods 中的React文件夹,it should be taken from node_modules.
-
问题11
rn-fetch-blob (from `../node_modules/rn-fetch-blob`) was resolved to 0.10.6, which depends on React/Core
解决办法: 1.检查podfile有无错误,2.删除ios外面一层的node_modules,3.npm i重新安装包依赖,4.pod install
-
问题12
react-native/third-party/glog-0.3.4
Showing All Messages /Users/aiyouwei/Documents/company/project/senseware/gzywApp/node_modules/react-native/React/configure:1:1: in `/Users/aiyouwei/Documents/company/project/senseware/gzywApp/node_modules/react-native/third-party/glog-0.3.4':
# 解决方法: cd gzywApp/node_modules/react-native/third-party/glog-0.3.4 ./configure make make install
-
问题13
Undefined symbols for architecture x86_64: JSClassCreate
解决办法:
Make sure JavaScriptCore.framework is added to "Link Binary With Libraries".
-
问题14
AppDelegate.m normal x86_64 objective-c com.apple.compilers.llvm.clang.1_0.compiler
**解决办法:**尝试修改
-
问题15
error: Build input file cannot be found: '/Users/aiyouwei/Documents/company/project/duwenlong/gzywapp/gzywApp/node_modules/react-native/Libraries/WebSocket/libfishhook.a'
解决方法
下载一个libfishhook.a文件到/node_modules/react-native/Libraries/WebSocket/
下
libfishhook.a 可以点击下载
16. 问题16
Xcode没有设备选择
```
a build only device cannot be used to run this target
```
**解决方法:**将app iOS Deployment Target 修改为较低版本,例如修改为12,基本上都合适