LoginSignup
3
1

More than 1 year has passed since last update.

M1 Mac + Xcode 12.5.1でReact Native 0.65 アプリのビルド時に出たエラーと対応

Last updated at Posted at 2021-12-24

この記事はReact Native Advent Calendar 2021の24日目の記事です。

React Nativeでは0.66からM1やXcode 13サポートが入ったのですが、それ以前のバージョンである0.65.1とXcode 12.5.1でビルドを試みた時に出たエラーをまとめます。結果としては、Xcode 12.5.1でもシミュレーターを使用しない(Any iOS Device (arm64))場合はビルドが成功しましたが、シミュレーター起動するとエラーになってしまう状況です。

環境

  • MacBook Pro (14-inch, 2021), Apple M1 Pro
  • macOS Monterey 12.0.1
  • React Native 0.65.1
  • Xcode 12.5.1
  • node 14.17.0(エラーになるので後にアップデート)
  • react-native-maps 0.25.0 (エラーになるので後にアップデート)

React NativeのApple Silicon (M1)とXcode 13サポート

公式ブログで、React Native 0.66からApple Silicon (M1)がXcode 13、iOS 15と共にサポートされたことがアナウンスされました。0.66を使うことで、この記事にあるエラーのうちいくつかはなくなると期待されます。

Xcode 12.5.1 が Monterey でサポートされていない対応

MontereyではXcode 12.5.1が起動できませんでした。Xcode 13はReact Native 0.66でサポートされたのですが、ビルドしたいアプリは0.65.1なので、Xcode 12.5.1でビルドする必要がありました。

対応策

Applicationsフォルダに Xcode 12.5.1 をインストール後、以下のコマンドで Monterey でも Xcode 12.5.1 が起動可能です。

/Applications/Xcode-12.5.1.app/Contents/MacOS/Xcode

FATAL ERROR: wasm code commit Allocation failed - process out of memory

ビルド時に以下のエラーが出ました。

FATAL ERROR: wasm code commit Allocation failed - process out of memory

対応策

nodeのバージョンをv14.17.0以降にすることで、解決しました。

xcrun: error: SDK "iphoneos" cannot be located

ビルド時に以下のエラーが出ました。

checking whether the C compiler works... no
xcrun: error: SDK "iphoneos" cannot be located
xcrun: error: unable to lookup item 'Path' in SDK 'iphoneos'

対応策

Xcodeのパスを設定することで、解決しました。

sudo xcode-select --switch /Applications/Xcode.app

Xcodeでビルドすると node: No such file or directory

エラーログ

env: node: No such file or directory

対応策

以下の2つを実施しました。

1. Build Phasesの Bundle React Native code and imagesUpload Debug Symbols to Sentry にnodeのパスを追加

例 : export PATH="$HOME/.nodenv/shims:$PATH"

2. react-native-xcode.shを修正

issueを参考に、react-native-xcode.shを以下のように修正しました。

--- ./node_modules/react-native/scripts/react-native-xcode.sh   2021-10-09 02:10:24.000000000 +0200
+++ ./node_modules/react-native/scripts/react-native-xcode.sh   2021-10-09 02:32:09.000000000 +0200
@@ -81,7 +81,7 @@

 # Find path to Node
 # shellcheck source=/dev/null
-source "$RN_DIR/scripts/find-node.sh"
+source "$REACT_NATIVE_DIR/scripts/find-node.sh"

GoogleMapsがコンパイルできない(未解決)

エラーログ

ld: building for iOS Simulator, but linking in object file built for iOS, file '/Users/shoken/Git/kitchhike_apps/ios/Pods/GoogleMaps/Maps/Frameworks/GoogleMaps.framework/GoogleMaps' for architecture arm64

対応策

react-native-mapsのバージョンをv0.30.0上げたらビルドができたという情報がissueに上がっていました。

package.jsonを修正し、react-native-mapsのバージョンをv0.30.0に上げると、CocoaPodsで依存エラーが起きます。

[!] CocoaPods could not find compatible versions for pod "Google-Maps-iOS-Utils":
  In snapshot (Podfile.lock):
    Google-Maps-iOS-Utils (= 2.1.0)

  In Podfile:
    react-native-google-maps (from `../node_modules/react-native-maps`) was resolved to 0.30.0, which depends on
      Google-Maps-iOS-Utils (= 3.10.3)


You have either:
 * changed the constraints of dependency `Google-Maps-iOS-Utils` inside your development pod `react-native-google-maps`.
   You should run `pod update Google-Maps-iOS-Utils` to apply changes you've made.

その後、Google-Maps-iOS-UtilsとGoogleMaps の2つを、pod updateする。

pod update Google-Maps-iOS-Utils GoogleMaps

Xcode 12.5.1でシミュレーターを使用しない(Any iOS Device (arm64))場合はビルドが成功するようになりました。ただし、シミュレーター起動でのビルドだと、GoogleMapsがエラーになります。

12/1にアナウンスされた、M1対応のMaps SDK 6.0が使われているGoogleMaps 6.0.1にしたいのですが、 react-native-maps 0.30.0はGoogleMaps 5.1.0依存となっている状況です。

react-native-mapsに、GoogleMaps 5.x依存をなくし、バージョンを更新できないかというissueが上がっているので、こちらが対応されたらM1 Macでもビルドができるようになりそうです。

3
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1