问题溯源

最近更新了 Xcode 16, 构建 Flutter 项目并上传到 AppStore Connect 时, 发生了如下错误

Asset validation failed (90482)
Invalid Executable. The executable 'Runner.app/Frameworks/**/*.framework' contains bitcode. (ID: 39d6c8cc-2939-4098-9a86-22fec42a0fae)

Asset validation failed (90482)
Invalid Executable. The executable 'Runner.app/Frameworks/**/*.framework' contains bitcode. (ID: fc3dbf15-f6ec-4fbc-b8ba-aeadb292913d)

........and so on

其根本原因在于 Apple 早在 Xcode 14 的时候就已经开始废弃了 Bitcode, 只不过 Xcode 16 开始更加严格了,上传的时候就强制不允许 bitcode.

参考以及鸣谢

Invalid Executable. The executable 'appname.app/Frameworks/hermes.framework/hermes' contains bitcode. (ID: XXXX)
https://stackoverflow.com/questions/78993520

如上帖子讲述了关于如何 strip bitcode 的方案,不过是手动的, 我总结了一下,做成了自动化脚本, 大家需要的请自取噢

解决方案

ios/Podfile (视具体项目而定噢) 文件中的 post_install 钩子(hook) 下,添加如下脚本,即可完成自动化去除所有 framework 自带的 bitcode

  # start: bitcode strip
  bitcode_strip_path = `xcrun --find bitcode_strip`.chomp

  def strip_bitcode_from_framework(bitcode_strip_path, framework_path, framework_name)
    command = "#{bitcode_strip_path} #{framework_path} -r -o #{framework_path}"
    puts "Stripping bitcode from #{framework_name}: #{command}"
    system(command)
  end

  # scan all frameworks in Pods directory
  Dir.glob("Pods/**/*.{framework,xcframework}") do |framework|
    framework_name = File.basename(framework, File.extname(framework)) # 获取框架名称
    puts "Found framework: #{framework_name}"

    # scan all binary files in framework matching the framework name
    Dir.glob("#{framework}/**/#{framework_name}") do |binary_file|
      if File.file?(binary_file)
        puts "Found matching binary: #{binary_file}"
        strip_bitcode_from_framework(bitcode_strip_path, binary_file, framework_name)
      end
    end
  end
  # end: bitcode strip

写入如上配置以后, 最好在 flutter 项目执行一下 flutter clean, 然后再构建项目
构建完毕以后就可以上传到 AppStore Connect 啦

配置 DEMO 截图

如下是我的 Flutter 项目下的 ios/Podfile 配置截图, 可供参考

1727564350838.webp

最后修改:2024 年 09 月 29 日
如果觉得我的文章对你有用,请随意赞赏