본문 바로가기
TIL

[React Native] error Command failed: xcrun instruments -s

by 사탕공방 2023. 1. 28.

리액트 네이티브를 다루는 기술 책 57페이지를 보면

애플 실리콘 호환이 되지 않아 yarn ios 명령 실행시 에러가날 것에 대한 조치법이 나와 있습니다.

그러나 전 이 글 작성일(23.01.28) 기준 문제 없이 호환될 것이라 판단하였기 때문에 yarn ios를 과감히 실행해 보았습니다.

만...

역시나 에러와 마주치게 됩니다 :)

일단 전 Xcode는 14버전이 설치되어 있었고 구글링 해보니 xcode 버전 선택에 대한 재설정을 해주면 되는 것 같습니다.

https://stackoverflow.com/questions/68896553/react-native-or-xcode-unable-to-find-utility-instruments-not-a-developer-too

 

React Native or Xcode: unable to find utility "instruments", not a developer tool or in PATH

xcrun: error: sh -c '/Applications/Xcode-beta.app/Contents/Developer/usr/bin/xcodebuild -sdk /Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk -find

stackoverflow.com

아래의 명령으로 해결 :)

sudo xcode-select -r

인줄 알았으나 해결되지 않았다.

하여 책에 있는대로 ios/Podfile 에서 use_flipper!() 라는 코드를 검색하였는데 없었다.

구글링을 하다가 아래의 명령을 실행하라는 글을 발견하여 실행해보았다.

npx react-native doctor

결과는...?

Android
 ✓ JDK
 ✓ Android Studio - Required for building and installing your app on Android
 ✖ Android SDK - Required for building and installing your app on Android
   - Versions found: N/A
   - Version supported: 33.0.0
 ✓ ANDROID_HOME

오.. Android SDK를 ... 찾아야 하는데 못찾고 있습니다.

그런데 ios 실행이 안되는건데 여기 문제가 관련이 있나 싶지만..

일단 문제가 있는 것으로 보이니 해결하고 넘어갑시다.

Android Studio 설정에서 Android SDK Command-line Tools를 설치해줍니다. 

Install Android SDK Command-line Tools (latest)

그리고 33.0.0 버전을 지원한다고 하니 Android SDK Build-Tools에서 33.0.0 버전을 설치해줍니다.

아래 이미지 처럼 보이지 않는다면 우 하단에 Show Package Details를 체크하시면 나올거에요 :)


다시 npx react-native doctor 실행 - 깔끔!

Android
 ✓ JDK
 ✓ Android Studio - Required for building and installing your app on Android
 ✓ Android SDK - Required for building and installing your app on Android
 ✓ ANDROID_HOME

iOS
 ✓ Xcode - Required for building and installing your app on iOS
 ✓ CocoaPods - Required for installing iOS dependencies
 ✓ ios-deploy - Required for installing your app on a physical device with the CLI
 ✓ .xcode.env - File to customize Xcode environment

Errors:   0
Warnings: 0

하. 지. 만

여전히 yarn ios로는 실행되지 않고.. 책에 있는 use_flipper!()라는 코드는 없지만 그 다음 수행해야 하는 명령을 수행해 보았습니다.

cd ios
pod install

후.. 쉽지 않네요 ㅋㅋ glog라는 것을 설치하다가 에러가 발생하는 것으로 보입니다.

Installing glog (0.3.5)
[!] /bin/bash -c 
set -e
#!/bin/bash
# Copyright (c) Meta Platforms, Inc. and affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.

set -e

PLATFORM_NAME="${PLATFORM_NAME:-iphoneos}"
CURRENT_ARCH="${CURRENT_ARCH}"

if [ -z "$CURRENT_ARCH" ] || [ "$CURRENT_ARCH" == "undefined_arch" ]; then
    # Xcode 10 beta sets CURRENT_ARCH to "undefined_arch", this leads to incorrect linker arg.
    # it's better to rely on platform name as fallback because architecture differs between simulator and device

    if [[ "$PLATFORM_NAME" == *"simulator"* ]]; then
        CURRENT_ARCH="x86_64"
    else
        CURRENT_ARCH="arm64"
    fi
fi

# @lint-ignore-every TXT2 Tab Literal
if [ "$CURRENT_ARCH" == "arm64" ]; then
    cat <<\EOF >>fix_glog_0.3.5_apple_silicon.patch
diff --git a/config.sub b/config.sub
index 1761d8b..43fa2e8 100755
--- a/config.sub
+++ b/config.sub
@@ -1096,6 +1096,9 @@ case $basic_machine in
                basic_machine=z8k-unknown
                os=-sim
                ;;
+       arm64-*)
+               basic_machine=$(echo $basic_machine | sed 's/arm64/aarch64/')
+               ;;
        none)
                basic_machine=none-none
                os=-none
EOF

    patch -p1 config.sub fix_glog_0.3.5_apple_silicon.patch
fi

export CC="$(xcrun -find -sdk $PLATFORM_NAME cc) -arch $CURRENT_ARCH -isysroot $(xcrun -sdk $PLATFORM_NAME --show-sdk-path)"
export CXX="$CC"

# Remove automake symlink if it exists
if [ -h "test-driver" ]; then
    rm test-driver
fi

# Manually disable gflags include to fix issue https://github.com/facebook/react-native/issues/28446
sed -i.bak -e 's/\@ac_cv_have_libgflags\@/0/' src/glog/logging.h.in && rm src/glog/logging.h.in.bak
sed -i.bak -e 's/HAVE_LIB_GFLAGS/HAVE_LIB_GFLAGS_DISABLED/' src/config.h.in && rm src/config.h.in.bak

./configure --host arm-apple-darwin

cat << EOF >> src/config.h
/* Add in so we have Apple Target Conditionals */
#ifdef __APPLE__
#include <TargetConditionals.h>
#include <Availability.h>
#endif

/* Special configuration for ucontext */
#undef HAVE_UCONTEXT_H
#undef PC_FROM_UCONTEXT
#if defined(__x86_64__)
#define PC_FROM_UCONTEXT uc_mcontext->__ss.__rip
#elif defined(__i386__)
#define PC_FROM_UCONTEXT uc_mcontext->__ss.__eip
#endif
EOF

# Prepare exported header include
EXPORTED_INCLUDE_DIR="exported/glog"
mkdir -p exported/glog
cp -f src/glog/log_severity.h "$EXPORTED_INCLUDE_DIR/"
cp -f src/glog/logging.h "$EXPORTED_INCLUDE_DIR/"
cp -f src/glog/raw_logging.h "$EXPORTED_INCLUDE_DIR/"
cp -f src/glog/stl_logging.h "$EXPORTED_INCLUDE_DIR/"
cp -f src/glog/vlog_is_on.h "$EXPORTED_INCLUDE_DIR/"

patching file config.sub
1 out of 1 hunks failed--saving rejects to config.sub.rej

심호흡하고 구글링하다가 공식문서 보고 아래와 같은 프로세스를 따르기로 함

npm uninstall -g react-native-cli @react-native-community/cli
npx react-native init ProjectName

Installing Bundler 과정에서 ruby 2.7.6이 필요하다고 에러 발생...

✖ Installing Bundler

https://codecamper.me/blog/122/ 블로그를 보고 ruby 2.7.6 버전 설정 후 npx react-native init ProjectName 재시도

✖ Installing CocoaPods dependencies

공식문서 가이드대로 설치

sudo gem install cocoapods

다시 프로젝트 생성 시도!

npx react-native init ProjectName

하지만 해결되지 않았다.. 

ios 가능하게 하기 어렵군요..

pod install 실행시 glog 설치 쉘 스크립트에 에러가 있습니다..크흡


23.11.22 해결글 올렸습니다.

https://spinse.tistory.com/591

 

[React Native] M1 Pro ios pod install glog (0.3.5) 설치 에러

환경 M1 Pro Macbook react-native: 0.72.7 ruby 2.6.10 cocoapods 1.14.3 문제 설치에 참고한 공식문서 bundle exec pod install 시 glog 설치 실패( 아래는 에러 메시지 ) Installing glog (0.3.5) [!] /bin/bash -c set -e #!/bin/bash # Copyr

spinse.tistory.com

 

댓글