1. 程式人生 > 實用技巧 >【轉】RN報錯彙總

【轉】RN報錯彙總

原文網址:https://www.jianshu.com/p/804dac985411

1. react-native init #projName# 報錯:

 info There appears to be trouble with your network connection. Retrying...
error An unexpected error occurred: "http://registry.npm.taobao.org/@babel/plugin-proposal-class-properties/download/@babel/plugin-proposal-class-properties-7.3.0.tgz: Client network socket disconnected before secure TLS connection was established".

映象不對,檢查映象是否為taobao的映象,

npm config list
//或者
npm config get registry
npm config set registry https://registry.npm.taobao.org/
//或者註冊華為的
npm config set registry https://mirrors.huaweicloud.com/repository/npm/

iOS

1. Cocoapods下的第三方庫libReact.a多個路徑

:-1: Multiple commands produce '/Users/***/Library/Developer/Xcode/DerivedData/sentryCpush-cvpqbragxhlzloeebvyoihyauasl/Build/Intermediates.noindex/ArchiveIntermediates/sentryCpush/IntermediateBuildFilesPath/UninstalledProducts/iphoneos/libReact.a':
1) Target 'React' has a command with output '/Users/***/Library/Developer/Xcode/DerivedData/sentryCpush-cvpqbragxhlzloeebvyoihyauasl/Build/Intermediates.noindex/ArchiveIntermediates/sentryCpush/IntermediateBuildFilesPath/UninstalledProducts/iphoneos/libReact.a'
2) Target 'React' has a command with output '/Users/***/Library/Developer/Xcode/DerivedData/sentryCpush-cvpqbragxhlzloeebvyoihyauasl/Build/Intermediates.noindex/ArchiveIntermediates/sentryCpush/IntermediateBuildFilesPath/UninstalledProducts/iphoneos/libReact.a'
  • 解決方式
    在Podfile中新增:
post_install do |installer|
  installer.pods_project.targets.each do |target|
    
    # The following is needed to ensure the "archive" step works in XCode.
    # It removes React & Yoga from the Pods project, as it is already included in the main project.
    # Without this, you'd see errors when you archive like:
    # "Multiple commands produce ... libReact.a"
    # "Multiple commands produce ... libyoga.a"
    
    targets_to_ignore = %w(React yoga)
    
    if targets_to_ignore.include? target.name
      target.remove_from_project
    end
    
  end
end

2. Staging 打包報錯:

問題

:-1: "sentryCpush" requires a provisioning profile. Select a provisioning profile for the "Staging" build configuration in the project editor. (in target 'sentryCpush')

或者

directory not found for option '-L/Users/***/Library/Developer/Xcode/DerivedData/qifutong-avakrnqhxoxkxdcqxbgxzehdkoeg/Build/Products/Staging-iphonesimulator/yoga'
  • 解決方法
    1、前提是你沒有改過所有Staging載入的路徑,
    或者你改過的話,看一下所有Staging載入的路徑,都必須還是Staging環境下的,沒有手動改為Release。eg:/$(CONFIGURATION)沒有被Release代替
$(BUILD_DIR)/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)

2、需要修改兩處
(1)、工程的build Settings 中 Per-configuration Build Products Path 的 Staging,修改為 Release

$(BUILD_DIR)/Release$(EFFECTIVE_PLATFORM_NAME)

(2)、Pods的工程,build Settings 中 Per-configuration Build Products Path 的 Staging,修改為 Release

$(BUILD_DIR)/Release$(EFFECTIVE_PLATFORM_NAME)

如果Pod中沒有Staging環境,info的Configurations 點選 + 號,新增Release Configuration ,然後把新新增的修改名稱為Staging,再更改Per-configuration Build Products Path

3、library not found for -lPods-myapp
重新link了下, pod update,xcode進行clear操作,突然就好了,至今是個謎,有些糾結。。。

3. library not found for -lRCTWebSocket 或者 glog no found 或者 libfishhook.a

cd node_modules/react-native/third-party/glog-0.3.5
../../scripts/ios-configure-glog.sh

4. _RCTSetLogFunction 報錯

Undefined symbols for architecture arm64:   "_RCTSetLogFunction", referenced from:       -[PropertyFinderTests testRendersWelcomeScreen] in PropertyFinderTests.o ld: symbol(s) not found for architecture arm64 clang: error: linker command failed with exit code 1 (use -v to see invocation)

解決:
Build Setting 中設定 Dead Code StrippingNo

5. iOS使用cocoapods 安裝libwebp 錯誤Error installing libwebp

原因:pod repo中libwebp的地址是谷歌的
解決辦法:
1、
pod repo
2、在本地庫中, 並找到對應的libwebp版本的檔案 執行命令
find ~/.cocoapods/repos/master -iname libwebp
3、 Finder中修改libwebp.podspec.json檔案
(command+shift+G)~/.cocoapods/repos/master/Specs/1/9/2/libwebp
4、把source - git中的url更換成https://github.com/webmproject/libwebp.git
然後儲存
5、最後重新執行pod install

注:
1、如果仍舊報了錯誤: error: RPC failed; curl 56 LibreSSL SSL_read: SSL_ERROR_SYSCALL, errno 54
解決方法:
git clone https://git.coding.net/CocoaPods/Specs.git ~/.cocoapods/repos/master
2、如果仍舊報錯:
解決方法:開啟Finder 使用快捷鍵 shift+command+G ,然後輸入 /應用程式/Xcode.app/Contents/Developer
回車;進入到對應的檔案

開啟終端 ,輸入 sudo xcode-select -switch 然後將上面檔案Developer 拖到終端輸入的命令sudo xcode-select -switch 後面
如下 sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer 回車
然後 終端輸入 pod setup

Android

1. SSL的錯誤,gradle版本下載不下來

解決方法: gradle.properties => systemProp 的配置全部隱藏

2. Manifest merger failed : Android

解決方法:Add to your package level android/build.gradle in buildscript -> ext:

 googlePlayServicesVersion = "16.+"
    firebaseVersion = "17.6.0"
3. Unable to load script. Make sure you're either running a Metro server (run 'react-native start') or that your bundle is packaged correctly for release.

解決方法:You need to change your target sdk to 27 instead of 28 in your project level build.gradle. From Android P(28), Google ban the use of http.

4. libfishhook.a

vi node_modules/react-native/third-party/glog-0.3.4/src/signalhandler.cc
At Line 78, change: return (void*)context->PC_FROM_UCONTEXT; to return NULL;


react native _RCTSetLogFunction

1.Opened XCode and pressed cmd + 1
2.Clicked on my project in the left panel, my target in the middle panel
3.Clicked on "Build Settings"
4.In the "Linking" section, under the "Dead Code Stripping" section, changed the setting for "Release" from "Yes" to "No"

Dead Code Stripping,Link With Standard Libraries

3.3.2 Dead Code Stripping > YES;(YES,消除無效程式碼)

For statically linked executables, dead-code stripping is the process of removing unreferenced code from the executable file. If the code is unreferenced, it must not be used and therefore is not needed in the executable file. Removing dead code reduces the size of your executable and can help reduce paging.

To enable dead-code stripping in Xcode, in the Linking group of Build Settings, set the Dead Code Stripping option to Yes.

3.3.3 Link With Standard Libraries > YES;

預設是YES,編譯器在連結時會自動使用標準庫的連結器;

看網上好多資料都說要改成NO,但是看官方的文件,如果設定為NO,需要配置 Other Linker Flags 來指定連結器。