React Native iOS App 빌드 스크립트

2022. 7. 20. 02:55서버 프로그래밍

React Native 프로젝트에서 Android App 빌드는 어렵지 않은데, iOS App 빌드는 상대적으로 복잡하다.

물론 fastlane을 이용하면 빌드 뿐만 아니라 배포도 수월하지만, fastlane의 도움 없이 console에서 빌드하는 스크립트를 작성해서 GitLab CI/CD 파이프라인에 적용하여 보았다.

https://www.reactnative.guide/11-devops/11.2-ios-build-setup.html

 

iOS Build setup | React Made Native Easy

  EditiOS build scripts/setup iOS builds via command line are much more complex as compared to Android. Note: Builds work only for Mac users. Since Apple requires that all the builds be made on Xcode itself, iOS apps can only be built on a Mac machine. T

www.reactnative.guide

  1. Place the provisioning profile at scripts/ios/profile/XYZ.mobileprovision
  2. Place the certificate at scripts/ios/certs/ABC.p12
  3. Place an exportOptions file at scripts/ios/exportOptions/exportOptions-dev.plist
  4. Create the script: The below script will create a new keychain ios-build and will store the certificate in the keychain. Also, it will make ios-build the default keychain so that Xcode picks up the certificate from it. Then it will copy the provisioning profile to the correct directory so that Xcode can pick it up.
  5. Create the script that does the build. This script will run the xcodebuild to first archive the project. Then it will generate the IPA file which can be used for installing the app onto an iPhone.

인증서를 지정되어 있는 폴더 (profile, certs)에 제대로 집어 넣고, exportOptions-dev.plist 파일과 두개의 쉘스크립트 파일만 제대로 세팅하면 어렵지 않게 성공시킬수 있다.

1) 처음에는 빌드시 인증서 관련 오류가 발생해서, 생각해보니 빌드 머신으로 사용하는 MacMini에 인증서를 설치하지 않았기 때문이었다. 그래서 다음을 참고해서 인증서를 설치하니 빌드는 정상적으로 진행됨

https://zeddios.tistory.com/327

 

Command /usr/bin/codesign failed with exit code 1 에러 해결

주의 그렇다고 하네요.. 밑에 내용은 쓰루해주시길 바랍니다. 따라하지마세요. 일단.. 근데 사실 확인이 안되어서 삭제는 보류중입니다. 으아ㅏ아아ㅏ 그냥 새 Command Line Tool만들어서 코딩하려는

zeddios.tistory.com

 

2) 빌드는 성공했지만 exportOptions-dev.plist 파일로 IPA 파일 생성 시에 provisioning profile 관련 오류가 발생을 해서 이것 저것 테스트해보니 provisioningProfiles 관련 세팅이 누락되었기 때문이었다. 다음과 같이 수정해서 최종적으로 성공.

 <?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
 <plist version="1.0">
 <dict>
     <key>compileBitcode</key>
     <false/>
     <key>method</key>
     <string>app-store</string>
     <key>teamID</key>
     <string>ABC1234DA</string>
     <key>uploadBitcode</key>
     <true/>
     <key>uploadSymbols</key>
     <true/>
     <key>signingStyle</key>
     <string>manual</string>
     <key>provisioningProfiles</key>
     <dict>
         <key>com.test.app</key>
         <string>TestProvisioningProd</string>
     </dict>
 </dict>
 </plist>

 

MacMini에 gitlab-runner를 설치해서 빌드 머신으로 사용해서, 빌드해보니 약 10분이 넘는 빌드 시간이 걸린다. 허허허.