Xcode 12 编译失败,咋办?RN报错、crash解决办法

2,157 阅读1分钟

因为Apple的arm64的电脑还没发布,还不存在arm64架构的模拟器。

1、在Build settings 里搜索 EXCLUDED_ARCHS 在Debug下添加 Any iOS Simulator SDK 值为 arm64

如图:

2、在Podfile里添加修改build_settings的代码

target 'XcodeDemo' do
  pod 'AFNetworking'
  post_install do |installer|
    installer.pods_project.build_settings('Debug')['EXCLUDED_ARCHS[sdk=iphonesimulator*]'] = 'arm64'
  end
end

如图:


3、React native 报错 、crash 咋办?

1. art 库在Xcode 12 报错,有人提出了修改办法

github.com/react-nativ…
项目中阴影颜色只有一种,我的临时解决办法是
github.com/dacaiguoguo…
坏处是RN代码设置的颜色就没有意义了。

2. 图片显示不出来?加几行代码就行了

github.com/dacaiguoguo… 相关问题讨论在:
github.com/facebook/re…

3. 编译报错说头文件找不到,link也报错。Xcode 12 可能改了framework的搜索算法。

cocoapods支持在podspec文件里增加脚本 guides.cocoapods.org/syntax/pods…
forkreact-native,改了React-Core.podspec
github.com/dacaiguoguo…

4. 修改package.json,注意语法是url后加#<commitId>,执行yarn install

"@react-native-community/art": "https://github.com/dacaiguoguogmail/art.git#c008c11be9f41adaba6f755ee3bd929585328104",
"react-native": "https://github.com/dacaiguoguogmail/react-native.git#0cc3c8beadf5a90be33e7223f54a88852c90a6ed",

5. 修改Podfile。改变xcconfig文件里的framework搜索路径,执行pod install

    find_path = installer.sandbox.root + 'Target Support Files'
    Find.find(find_path) do |filename|
      next unless filename.end_with? '.xcconfig'

      puts filename
      File.open(filename, 'r') do |lines|
        org_string = lines.read
        if org_string.valid_encoding?
          buffer = org_string.gsub('"${PODS_CONFIGURATION_BUILD_DIR}/React-Core"', '"${PODS_CONFIGURATION_BUILD_DIR}/React"')
          File.open(filename, 'w') do |l|
            l.write(buffer)
          end
        end
      end

编译运行,终于没问题了