You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

在iOS模拟器运行Flutter应用时遭遇arm64架构不兼容错误的技术求助

Fix Flutter iOS Simulator Build Failure (arm64 Architecture Mismatch with Sodium)

Hey there, I’ve run into this exact arm64 architecture conflict with Flutter and third-party pods like Sodium before. The error happens because the libsodium-ios.a static library is compiled for iOS physical devices (arm64) but you’re trying to run on the iOS Simulator—even on M-series Macs, the simulator uses a specialized arm64 variant that’s incompatible with device-built binaries.

Here’s the Flutter-specific fix (no native iOS workaround hacks needed):

Step 1: Update Your Podfile

Modify the post_install block in your ios/Podfile to exclude simulator architectures for problematic pods, while keeping Flutter’s default build settings intact. Here’s the updated full Podfile:

# Uncomment this line to define a global platform for your project
platform :ios, '10.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__))
end

post_install do |installer|
  installer.pods_project.targets.each do |target|
    flutter_additional_ios_build_settings(target)
    
    # Add these lines to fix architecture mismatch
    target.build_configurations.each do |config|
      # Exclude arm64 for iOS Simulator
      config.build_settings['EXCLUDED_ARCHS[sdk=iphonesimulator*]'] = 'arm64'
      
      # For M-series Macs, also ensure we don't force arm64 for simulator
      config.build_settings['VALID_ARCHS[sdk=iphonesimulator*]'] = 'x86_64 arm64'
    end
    
    # If Sodium is still causing issues, explicitly set its architectures
    if target.name == 'Sodium'
      target.build_configurations.each do |config|
        config.build_settings['ARCHS[sdk=iphoneos*]'] = 'arm64'
        config.build_settings['ARCHS[sdk=iphonesimulator*]'] = 'x86_64'
      end
    end
  end
end

Step 2: Clean and Rebuild

Run these commands in order to apply the changes properly:

  • Navigate to your project’s iOS directory: cd ios
  • Deintegrate existing pods: pod deintegrate
  • Reinstall pods: pod install
  • Clean your Flutter project: flutter clean
  • Run the app on the simulator: flutter run

Why This Works

  • The EXCLUDED_ARCHS setting tells Xcode not to try linking arm64 binaries for the simulator, avoiding the mismatch with Sodium’s device-only library.
  • The explicit Sodium target configuration ensures it builds for the correct architecture per platform (device vs simulator).
  • We keep flutter_additional_ios_build_settings(target) intact to preserve Flutter’s default build rules, so we don’t break other parts of the project.

If you’re on an M-series Mac and still run into issues, try opening Xcode via Rosetta (right-click Xcode > Get Info > Check "Open using Rosetta")—this forces the simulator to use x86_64 architecture, which avoids the arm64 conflict entirely.

内容的提问来源于stack exchange,提问作者Mokhtar Ghaleb

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.28 13:07:40