文章

MacOS Big Sur后GN生成WebRTC工程报错

生成工程命令:

gn gen out/ios_64_debug –args=’target_os=”ios” target_cpu=”arm64” ios_enable_code_signing=false’ –ide=xcode

报错:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
ERROR at //build/config/mac/mac_sdk.gni:106:7: Script returned non-zero exit code.
      exec_script("//build/mac/find_sdk.py", find_sdk_args, "list lines")
      ^----------
Current dir: /Users/admin/Repos/webrtc_all/webrtc/src/out/ios_64_debug/
Command: python /Users/admin/Repos/webrtc_all/webrtc/src/build/mac/find_sdk.py --print_sdk_path --print_bin_path 10.12
Returned 1.
stderr:

Traceback (most recent call last):
  File "/Users/admin/Repos/webrtc_all/webrtc/src/build/mac/find_sdk.py", line 97, in <module>
    print(main())
  File "/Users/admin/Repos/webrtc_all/webrtc/src/build/mac/find_sdk.py", line 80, in main
    raise Exception('No %s+ SDK found' % min_sdk_version)
Exception: No 10.12+ SDK found

See //build/toolchain/mac/BUILD.gn:15:1: whence it was imported.
import("//build/config/mac/mac_sdk.gni")
^--------------------------------------
See //BUILD.gn:29:3: which caused the file to be included.
  group("default") {
  ^-----------------

Exception: No 10.12+ SDK found, 大意就是10.12+ 的SDK找不到,报错文件webrtc/src/build/mac/find_sdk.py 80行。代码如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
  if not os.path.isdir(sdk_dir):
    raise SdkError('Install Xcode, launch it, accept the license ' +
      'agreement, and run `sudo xcode-select -s /path/to/Xcode.app` ' +
      'to continue.')
  sdks = [re.findall('^MacOSX(10\.\d+)\.sdk$', s) for s in os.listdir(sdk_dir)]
  sdks = [s[0] for s in sdks if s]  # [['10.5'], ['10.6']] => ['10.5', '10.6']
  sdks = [s for s in sdks  # ['10.5', '10.6'] => ['10.6']
          if parse_version(s) >= parse_version(min_sdk_version)]
  if not sdks:
    raise Exception('No %s+ SDK found' % min_sdk_version)
  best_sdk = sorted(sdks, key=parse_version)[0]


因为MacOS Big Sur版本号改为了11.x,程序搜索的版本号是10开头的,所以查找不到,改为11后 work fine:

1
2
  sdks = [re.findall('^MacOSX(11\.\d+)\.sdk$', s) for s in os.listdir(sdk_dir)]

本文由作者按照 CC BY 4.0 进行授权