Flutter Engine macOS 编译与调试之Ubuntu下载

102 阅读1分钟

方法一、 更改 .gclient 配置

.gclient内容如下(替换为自己的Github Flutter Engine仓库)

solutions = [
  {
    "managed": False,
    "name": "src/flutter",
    "url": "https://github.com/flutter/engine.git",
    "custom_deps": {},
    "deps_file": "DEPS",
    "safesync_url": "",
    "custom_vars": {
        'host_os': "mac",     //指定系统
        'host_cpu': "arm64",  //指定cpu架构
    },
  },
]

方法二、 更改 depot_tools 文件配置

  1. gclient.py 文件的函数 _detect_host_os() 内容如下(更改自己的 depot_tools/gclient.py )
def _detect_host_os():
    if sys.platform in _PLATFORM_MAPPING:
        # return _PLATFORM_MAPPING[sys.platform]    
        return _PLATFORM_MAPPING['darwin']   //指定系统

    try:
        return os.uname().sysname.lower()
    except AttributeError:
        return sys.platform
  1. detect_host_arch.py 文件的函数 HostArch() 内容如下(更改自己的 depot_tools/detect_host_arch.py )
def HostArch():
    """Returns the host architecture with a predictable string."""
    host_arch = platform.machine().lower()
    host_processor = platform.processor().lower()

    # Convert machine type to format recognized by gyp.
    if re.match(r'i.86', host_arch) or host_arch == 'i86pc':
        host_arch = 'x86'
    elif host_arch in ['x86_64', 'amd64']:
        host_arch = 'x64'
    elif host_arch == 'arm64' or host_arch.startswith('aarch64'):
        host_arch = 'arm64'
    elif host_arch.startswith('arm'):
        host_arch = 'arm'
    elif host_arch.startswith('mips64'):
        host_arch = 'mips64'
    elif host_arch.startswith('mips'):
        host_arch = 'mips'
    elif host_arch.startswith('ppc') or host_processor == 'powerpc':
        host_arch = 'ppc'
    elif host_arch.startswith('s390'):
        host_arch = 's390'
    elif host_arch.startswith('riscv'):
        host_arch = 'riscv64'

    if host_arch == 'arm64':
        host_platform = platform.architecture()
        if len(host_platform) > 1:
            if host_platform[1].lower() == 'windowspe':
                # Special case for Windows on Arm: windows-386 packages no
                # longer work so use the x64 emulation (this restricts us to
                # Windows 11). Python 32-bit returns the host_arch as arm64,
                # 64-bit does not.
                return 'x64'

    # platform.machine is based on running kernel. It's possible to use 64-bit
    # kernel with 32-bit userland, e.g. to give linker slightly more memory.
    # Distinguish between different userland bitness by querying
    # the python binary.
    if host_arch == 'x64' and platform.architecture()[0] == '32bit':
        host_arch = 'x86'
    if host_arch == 'arm64' and platform.architecture()[0] == '32bit':
        host_arch = 'arm'

    # return host_arch
    return "arm64"   //指定cpu架构