Flutter のビルドで Error (Xcode): unsupported option '-G' for target 'x86
はじめに
今年に入ってから Flutter の勉強をしているのですが、サンプルプログラムを作っている際に遭遇したエラーについて記録しておきます。
Flutter 環境構築は以下の書籍を参考に設定しています。
Flutter実践開発 ── iPhone/Android両対応アプリ開発のテクニック
また今回作成していたサンプルプログラムは Udemy の「Flutterアプリ開発講座(初級編)」の Chapter 9 の TODO アプリです。
発生したエラー Error (Xcode): unsupported option '-G' for target 'x86_64-apple-ios10.0-simulator'
ビルド時に発生したエラーはこちらになります。
Launching lib/main.dart on iPhone 16 in debug mode...
Updating project for Xcode compatibility.
Upgrading project.pbxproj
Upgrading Runner.xcscheme
Running pod install...
Running Xcode build...
Xcode build done. 11.9s
Failed to build iOS app
Error (Xcode): unsupported option '-G' for target 'x86_64-apple-ios10.0-simulator'
Could not build the application for the simulator.
Error launching application on iPhone 16.
今回作っていたサンプルプログラムは Firebase を初めて利用したものでした。
確認のためにその前に作っていたプログラムでビルドしてみましたが正常にビルドできました。
そのため Firebase を利用したことによってビルドが失敗したのでは?とあたりをつけて調査しました。
ChatGPT に聞いてみたりもしましたが解決しませんでした。
そこで普通に検索してみると以下のページが見つかりました。
対応方法1
まずは以下のコメントを実施してみました。
This helped me, especially this part:
(In Xcode) On the row select Build Settings and search for and set it to yes ALLOW_NON_MODULAR_INCLUDES_IN_FRAMEWORK_MODULES = YES
Xcode 自体ほぼ触ったことがなかったので迷いましたが以下のように設定を変更しました。
もう一度ビルドを実行してみましたが結果は変わりませんでした。
対応方法2
次に以下を試してみました。
My solution for this problem, works fine with debug and release for me :)
https://stackoverflow.com/a/78651666/25662983
stackoverflow の次のページです。
次のコメント部分を参考に実行しました。
I'm using macOS 15.0 beta and Xcode 16 beta. After few a hours I solved the problem with this:
Podfile の変更
コメントの通りに ios/Podfile を変更してみます。
Before
# Uncomment this line to define a global platform for your project
# platform :ios, '12.0'
# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
ENV['COCOAPODS_DISABLE_STATS'] = 'true'
project 'Runner', {
'Debug' => :debug,
'Profile' => :release,
'Release' => :release,
}
def flutter_root
generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'Generated.xcconfig'), __FILE__)
unless File.exist?(generated_xcode_build_settings_path)
raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure flutter pub get is executed first"
end
File.foreach(generated_xcode_build_settings_path) do |line|
matches = line.match(/FLUTTER_ROOT\=(.*)/)
return matches[1].strip if matches
end
raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Generated.xcconfig, then run flutter pub get"
end
require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root)
flutter_ios_podfile_setup
target 'Runner' do
use_frameworks!
use_modular_headers!
flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))
target 'RunnerTests' do
inherit! :search_paths
end
end
post_install do |installer|
installer.pods_project.targets.each do |target|
flutter_additional_ios_build_settings(target)
end
end
After
# Uncomment this line to define a global platform for your project
platform :ios, '13.0' # 変更箇所
# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
ENV['COCOAPODS_DISABLE_STATS'] = 'true'
project 'Runner', {
'Debug' => :debug,
'Profile' => :release,
'Release' => :release,
}
def flutter_root
generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'Generated.xcconfig'), __FILE__)
unless File.exist?(generated_xcode_build_settings_path)
raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure flutter pub get is executed first"
end
File.foreach(generated_xcode_build_settings_path) do |line|
matches = line.match(/FLUTTER_ROOT\=(.*)/)
return matches[1].strip if matches
end
raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Generated.xcconfig, then run flutter pub get"
end
require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root)
flutter_ios_podfile_setup
target 'Runner' do
use_frameworks!
use_modular_headers!
pod 'Firebase/Analytics', :modular_headers => true # 追記
pod 'Firebase/Auth', :modular_headers => true # 追記
pod 'Firebase/Core', :modular_headers => true # 追記
pod 'Firebase/Firestore', :modular_headers => true # 追記
flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))
target 'RunnerTests' do
inherit! :search_paths
end
end
post_install do |installer|
installer.pods_project.targets.each do |target|
flutter_additional_ios_build_settings(target)
if target.name == 'BoringSSL-GRPC' # 追記
target.source_build_phase.files.each do |file| # 追記
if file.settings && file.settings['COMPILER_FLAGS'] # 追記
flags = file.settings['COMPILER_FLAGS'].split # 追記
flags.reject! { |flag| flag == '-GCC_WARN_INHIBIT_ALL_WARNINGS' } # 追記
file.settings['COMPILER_FLAGS'] = flags.join(' ') # 追記
end # 追記
end # 追記
end # 追記
end
end
続いて指示通りにコマンドを実行してみました。
% ruby --version
ruby 3.4.1 (2024-12-25 revision 48d4efcb85) +PRISM [arm64-darwin23]
% pod --version
1.16.2
% pod repo update
Updating spec repo `trunk`
% cd ios
% rm -rf Pods
% rm -rf ~/Library/Developer/Xcode/DerivedData/*
zsh: sure you want to delete all 8 files in /Users/xxxxxxxx/Library/Developer/Xcode/DerivedData [yn]? y
% pod cache clean --all
% pod install
Analyzing dependencies
cloud_firestore: Using Firebase SDK version '10.25.0' defined in 'firebase_core'
firebase_core: Using Firebase SDK version '10.25.0' defined in 'firebase_core'
Downloading dependencies
Installing BoringSSL-GRPC (0.0.32)
Installing Firebase (10.25.0)
Installing FirebaseAnalytics (10.25.0)
Installing FirebaseAppCheckInterop (10.29.0)
Installing FirebaseAuth (10.25.0)
Installing FirebaseCore (10.25.0)
Installing FirebaseCoreExtension (10.29.0)
Installing FirebaseCoreInternal (10.29.0)
Installing FirebaseFirestore (10.25.0)
Installing FirebaseFirestoreInternal (10.25.0)
Installing FirebaseInstallations (10.29.0)
Installing FirebaseSharedSwift (10.29.0)
Installing Flutter (1.0.0)
Installing GTMSessionFetcher (3.5.0)
Installing GoogleAppMeasurement (10.25.0)
Installing GoogleUtilities (7.13.3)
Installing PromisesObjC (2.4.0)
Installing RecaptchaInterop (100.0.0)
Installing abseil (1.20240116.2)
Installing cloud_firestore (4.17.5)
Installing firebase_core (2.32.0)
Installing gRPC-C++ (1.62.5)
Installing gRPC-Core (1.62.5)
Installing leveldb-library (1.22.6)
Installing nanopb (2.30910.0)
Generating Pods project
Integrating client project
Pod installation complete! There are 7 dependencies from the Podfile and 25 total pods installed.
[!] CocoaPods did not set the base configuration of your project because your project already has a custom config set. In order for CocoaPods integration to work at all, please either set the base configurations of the target `Runner` to `Target Support Files/Pods-Runner/Pods-Runner.profile.xcconfig` or include the `Target Support Files/Pods-Runner/Pods-Runner.profile.xcconfig` in your build configuration (`Flutter/Release.xcconfig`).
pod install
上手く行ってるみたいです!
最後になんか気になるメッセージは出ていますが、とりあえずこの状態でビルドできるか試してみます。
Launching lib/main.dart on iPhone 16 in debug mode...
Running pod install...
Running Xcode build...
Xcode build done. 408.3s
Debug service listening on ws://127.0.0.1:57919/ItrVZyi2rEc=/ws
Syncing files to device iPhone 16...
ビルド出来ました🎉
さいごに
今回、Flutter から Firebase を初めて利用する際に遭遇したビルドエラーとその解決方法について共有しました。Flutter はまだまだわからないことだらけですがアプリが実機で動くと楽しいですね 😄
同じような問題に直面している方の参考になれば幸いです。
Discussion