分類
React Native

[React Native] 無法安裝App 因為無法驗證其完整性

Situation

使用企業內部 Ad Hoc 方式打包 ipa 後,iPhone 13 – iOS 15.5 安裝 ipa 時發生以下錯誤訊息

無法安裝App,因為無法驗證其完整性

已經確認在 Apple Develop 的 Devices 已加入裝置的UDID,但還是無法安裝 App

Action

首先可以透過 ipa_analyzer 檢查.ipa 檔允許安裝的裝置清單,如果裝置不在安裝清單中,基本上就可以確認問題了。

A.安裝 ipa_analyzer

開啟終端機輸入 gem install ipa_analyzer

B.使用 ipa_analyzer 檢查 .ipa

在終端機輸入 ipa_analyzer -i /path/xxx.ipa -p --info-plist --prov

輸出內容應該有個 “ProvisionedDevices” 區塊,檢查該區塊中是否有裝置UDID,沒有的話代表.ipa檔無法提供給裝置安裝。

C.解決方式尚待釐清(還不確定)

1.在 Xcode -> Preference -> Download Manual Profiles (可能要多按幾次)

2.在 ~/Library/MobileDevice/Provisioning Profiles/ 就會出現剛剛下載的Profile,可以預覽Profile其中的內容,應該會有最新加入的Devices

3.滑鼠右鍵雙擊剛剛下載的Profile,讓Xcode去套用它

4.使用 Xcode 重新 build 專案

5.這次產生的.ipa 應該就可以安裝到新裝置上了

Result

錯誤訊息不再出現,新打包的 .ipa 檔可以安裝在新裝置。

分類
React Native

[React Native] xcrun: error: unable to find utility “instruments”, not a developer tool or in PATH

Situation

使用 React Native 0.55.4 搭配 Xcode 13 執行 npx react-native run-ios 出現以下錯誤訊息,

xcrun: error: sh -c '/xxx/Xcode/Xcode_13.app/Contents/Developer/usr/bin/xcodebuild -sdk /xxx/Xcode/Xcode_13.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk -find instruments 2> /dev/null' failed with exit code 17664: (null) (errno=Invalid argument)

xcrun: error: unable to find utility "instruments", not a developer tool or in PATH

重點在於 xcrun: error: unable to find utility “instruments”, not a developer tool or in PATH

Action

出現以上錯誤的原因在於Xcode 13的 xcrun 已經沒有 instruments 參數,可以使用 xcrun simctl list 來取代。

接著說明如何修改以及修改哪個檔案。

首先當你輸入 npx react-native run-ios 指令後,node 會執行ReactNative專案目錄/node_modules/react-native/local-cli/runIOS/runIOS.js。(這也是我們要修改的檔案)

打開 ReactNative專案目錄/node_modules/react-native/local-cli/runIOS/runIOS.js,移動到下方區塊

const devices = parseIOSDevicesList(
   child_process.execFileSync('xcrun', ['instruments', '-s'], {encoding: 'utf8'})

這就是出問題的位置。把 execFilesync方法的第2個參數改為 ['simctl', 'list'] 即可,如下

  child_process.execFileSync('xcrun', ['simctl', 'list'], {encoding: 'utf8'})

Result

錯誤訊息不再出現,通過編譯!!

分類
React Native

[React Native] ld: in /xxx/AppCenter(MSChannelUnitConfiguration.o) building for iOS Simulator , but linking in object file built for iOS, File xxx for architecture arm64

Situation

使用Xcode 13建置ReactNative專案的iOS目錄(執行Xcode的Build)後且在建置過程出現以下錯誤訊息

ld: in /ReactNativeProject/ios/Pods/AppCenter/AppCenter-SDK-Apple/iOS/AppCenter.framework/AppCenter(MSChannelUnitConfiguration.o), building for iOS Simulator, but linking in object file built for iOS, file '/ReactNativeProject/ios/Pods/AppCenter/AppCenter-SDK-Apple/iOS/AppCenter.framework/AppCenter' for architecture arm64

Action

解法參考 https://stackoverflow.com/questions/63607158/xcode-building-for-ios-simulator-but-linking-in-an-object-file-built-for-ios-f

簡單的說就是到Xcode的Build Settings -> Excluded Architectures -> 加入Debug 和 Release 為 Any iOS Simulator SDK 等於 arm64 的設定,如下

Result

錯誤訊息不再出現

分類
React Native

[React Native] ERROR Metro Bundler can’t listen on port 8081

Situation

在Terminal輸入 npm start ,Console回應 ERROR Metro Bundler can’t listen on port 8081

Action

在MAC上先使用 sudo lsof :8081 查詢哪些服務使用8081,接著再輸入 kill -9 PID 號碼 來終止該服務,如下

%sudo lsof -i :8081
COMMAND   PID       USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
node    20537       user   40u  IPv6 11ae1baafc8ed7aa87      0t0  TCP *:sunproxyadmin (LISTEN)
%kill -9 20537

Result

輸入 npm start 之後可重新啟動

分類
React Native

[React Native] build failure : DeviceException: No connected devices!

Situation

在編譯 Android 版本時,輸入 npx react-native run-android,console 回應 com.android.builder.testing.api.DeviceException: No Connected devices,如下

Action

透過 Android Studio – AVD Manager 啟動虛擬裝置或將直接連接實體裝置皆可

Result

錯誤不再出現

分類
React Native

[React Native] build failure : The SDK directory ‘xxx’ does not exist

Situation

輸入 npx react-native run-android,console 回應 The SDK directory ‘xxx’ does not exist,如下

Action

到專案根目錄/android/ 找 local.properties 檔案,如果沒有就建立一個。

接著開啟該檔案並查找sdk.dir,確認sdk.dir是否正確對應到已安裝的Android SDK path。

Result

該錯誤不再出現

分類
React Native

[React Native] unknown argument type '__attribute__' in method

Situation

透過 Terminal 執行 React Native IOS版本時出現死亡紅幕,
執行指令為

npx react-native run-ios --device "device phone name"

死亡紅幕內容如下

Unknown argument type '__attribute__' in method -[RCTUIManager setJSResponder:blockNativeResponder:]

or

Unknown argument type '__attribute__' in method -[RCTAppState getCurrentAppState:error:]
...

Action

遇到相同問題的人還不少,找到以下這篇(https://stackoverflow.com/questions/58051510/xcode-11-0-build-get-error-unknown-argument-type-attribute-in-method-r)
作法就是修改 /專案目錄/node_modules/react-native/React/Base/RCTModuleMethod.mm 的 RCTParseUnused 方法,改為以下內容

static BOOL RCTParseUnused(const char **input)
{
  return RCTReadString(input, "__attribute__((unused))") ||
           RCTReadString(input, "__attribute__((__unused__))") ||
           RCTReadString(input, "__unused");
}

重點要記得最好把原本的 app 刪除,重新使用 terminal 執行
npx react-native run-ios –device “device phone name” 來安裝並執行,App才會顯示正常。

Result

該錯誤訊息和死亡紅幕不再出現,App 正常運作。
 

分類
React Native

[React Native] gflag.h not found

1.開啟終端機移動到 專案目錄/node_modules/react-native/thrid-party/glog-0.3.4
2.接著在該目錄中執行 ../../scripts/ios-configure-glog.sh

分類
React Native

[React Native] Config.h not found

使用 Xcode 載入並編譯 ReactNatie 的 ios項目時出現“Config.h not found” in mutex.h
移動到 /專案目錄/node_modules/react-native/third-party/glog-0.3.4/
執行 ./configure
再執行 make
解決該問題之後,重新編譯發生 gflags.h not found。
參考此篇

分類
React Native

[React Native] Error: Unable to resolve module ModuleName from xxx.js

Error Message :

error: Error: Unable to resolve module react-navigation-redux-helpers from /project_path/App/Navigation/utils/redux.js: react-navigation-redux-helpers could not be found within the project or in these directories:
node_modules
If you are sure the module exists, try these steps:
1. Clear watchman watches: watchman watch-del-all
2. Delete node_modules and run yarn install
3. Reset Metro's cache: yarn start --reset-cache
4. Remove the cache: rm -rf /tmp/metro-*
2 | createReactNavigationReduxMiddleware,
3 | createReduxBoundAddListener,
> 4 | } from 'react-navigation-redux-helpers';
| ^
5 |
6 | const middleware = createReactNavigationReduxMiddleware(
7 | "root",

 
1.go to https://www.npmjs.com/ and input your missing module name as below

it will show match modules

 
3. click module link on page then show module info

4. Go to your project root directory and type install command in terminal
npm i react-navigation-redux-helpers
or using “rnpm installl react-navigation-redux-helpers” if you installed rnpm
5. Terminate running Node and restart it by type “npm start”
6. Press Reload JS button on Device