Xcode 16におけるBitcode関連エラーの解決方法
問題の概要
Xcode 16を使用してアプリをTestFlightに配布する際、以下のエラーが発生するケースが報告されています:
Invalid Executable. The executable 'appname.app/Frameworks/hermes.framework/hermes' contains bitcode. (ID: XXXX)
このエラーは、プロジェクト設定でENABLE_BITCODE=NO を指定しているにも関わらず発生します。主な特徴は:
- 特にReact NativeプロジェクトでHermesエンジンを使用している場合に頻発
- Xcode 15から16へのアップグレード後に発生
- TestFlightへのアップロード時(アーカイブ段階)で確認される
根本原因
AppleはXcode 16でBitcode処理ロジックを変更しました。これにより、特定条件下で:
- サードパーティライブラリ(例:Hermes)が内部でBitcodeを含んでいる
- Xcodeのプロジェクト設定が完全に適用されない
- アプリ実行ファイルにBitcodeが意図せず含まれてしまう
効果的な解決方法
方法1: Bitcode自動除去スクリプト(推奨)
最も確実なのはBitcodeをframeworkから物理的に除去する方法です:
- プロジェクトの
ios
ディレクトリにスクリプトを作成
#!/bin/bash
# Bitcodeの存在チェック
find Pods . -name '*.framework' -type d | while read framework; do
binary="${framework}/$(basename "$framework" .framework)"
[ -f "$binary" ] && otool -l "$binary" | grep -q __LLVM && \
echo "Bitcode found: $binary"
done
- Bitcode除去スクリプトを実行
#!/bin/bash
xcrun_bitcode_strip=$(xcrun --find bitcode_strip)
find Pods . -name '*.framework' -type d | while read framework; do
binary="${framework}/$(basename "$framework" .framework)"
[ -f "$binary" ] && otool -l "$binary" | grep -q __LLVM && \
"$xcrun_bitcode_strip" "$binary" -r -o "$binary"
done
- 実行権限付与とスクリプト実行
chmod +x strip_bitcode.sh
./strip_bitcode.sh
重要
スクリプト実行後はクリーンビルドが必要です:
xcodebuild clean -workspace YourProject.xcworkspace
rm -rf ~/Library/Developer/Xcode/DerivedData
方法2: CocoaPodsを利用する場合(簡易版)
Podfileにpost_installフックを追加:
post_install do |installer|
bitcode_strip_path = `xcrun --find bitcode_strip`.chop!
# Hermes向けのBitcode除去パス
framework_paths = [
"Pods/hermes-engine/destroot/Library/Frameworks/macosx/hermes.framework/hermes",
"Pods/hermes-engine/destroot/Library/Frameworks/universal/hermes.xcframework/**/hermes"
]
framework_paths.each do |path|
full_path = File.join(Dir.pwd, path)
if File.exist?(full_path)
system("#{bitcode_strip_path} #{full_path} -r -o #{full_path}")
end
end
end
適用手順:
pod deintegrate
pod install
方法3: 手動でframeworkを修正
特定のframeworkのみ修正する方法:
xcrun bitcode_strip \
path/to/ProjectName.app/Frameworks/hermes.framework/hermes \
-r -o path/to/ProjectName.app/Frameworks/hermes.framework/hermes
パスの特定方法
Frameworkの正確なパスは以下で確認可能:
- Xcodeの
Products
フォルダで.appファイルを右クリック Show in Finder
→Contents/Frameworks
検証手順
Bitcodeが正しく除去されたか確認:
otool -l path/to/hermes.framework/hermes | grep __LLVM
出力結果が何も返さなければ成功です。
補足事項
Xcodeダウングレードについて
一時的な解決策としてXcode 15.4へのダウングレードが提案されることもありますが、長期的には推奨されません。Appleは90日以内に新しいXcodeバージョンを要求するため、根本解決が必須です。
React Nativeプロジェクトの場合
Hermes 0.73以上を使用している場合、react-native.config.js
に以下を追加:
module.exports = {
dependencies: {
'hermes-engine': {
platforms: {
ios: null, // React Native側のHermes管理を無効化
},
},
},
};
よくある質問
Q: 全てのframeworkでBitcode除去が必要ですか?
A: check_bitcode.sh
スクリプトで検出されたframeworkのみ対象で充分です。通常はHermes関連ファイルが主原因です。
Q: この修正はApp Storeの審査に影響しますか?
A: いいえ、BitcodeはAppleのサーバーサイドコンパイル用オプション機能であり、除去してもアプリの動作や審査に影響しません。
Q: Bitcode設定はプロジェクトで無効化済みなのに何故エラーが?
A: Xcode 16のバグにより、サードパーティライブラリの内部設定が優先されるケースがあります。物理的な除去が最も確実です。
これらの手順により、Xcode 16環境でもBitcode関連エラーを解消し、TestFlightへの配布が可能になります。プロジェクト構成に応じた最適な方法を選択して実装してください。