-
Notifications
You must be signed in to change notification settings - Fork 29k
Description
Problem 😭
There are some errors if we setup flutter engine environment in standard way, including:
gclient sync
cannot find third_party/android_tools (including ndk and sdk) and third_party/java packages (openjdk) in arm64 on M1 chip macOS- Cannot download prebuilt Dart SDK in arm64, and some header in Dart check 32/64 bit machine matching failed
tools/gn
shows//out/android_debug/clang_x64/gen_snapshot
is not the right target, but it generates a target//out/android_debug/clang_arm64/gen_snapshot
instead and failed- objcopy command try to find the wrong path
- Some other errors
Related errors and failure images:
Workaround 😊
So I dig into the var host_cpu
and find it's maybe originally provided by depot_tools
, and I temporarily do some modification, force cpu_arch detech logics to x64 in depot_tools
as a workaround:
depot_tools$ git diff
diff --git a/cipd b/cipd
index 91fbe165..d1903d77 100755
--- a/cipd
+++ b/cipd
@@ -46,13 +46,13 @@ if [ -z $ARCH ]; then
ARCH="${UNAME}"
;;
aarch64)
- ARCH=arm64
+ ARCH=amd64
;;
armv7l)
ARCH=armv6l
;;
arm*)
- ARCH="${UNAME}"
+ ARCH="amd64"
;;
*86)
ARCH=386
diff --git a/detect_host_arch.py b/detect_host_arch.py
index cf4bfec7..6a4e8566 100755
--- a/detect_host_arch.py
+++ b/detect_host_arch.py
@@ -44,7 +44,7 @@ def HostArch():
if host_arch == 'arm64' and platform.architecture()[0] == '32bit':
host_arch = 'arm'
- return host_arch
+ return 'x64'
def DoMain(_):
"""Hook to be called from gyp without starting a separate python
diff --git a/gclient.py b/gclient.py
index 446be28d..71b087b5 100755
--- a/gclient.py
+++ b/gclient.py
@@ -1283,7 +1283,7 @@ class Dependency(gclient_utils.WorkItem, DependencySettings):
'checkout_ppc': 'ppc' in self.target_cpu,
'checkout_s390': 's390' in self.target_cpu,
'checkout_x64': 'x64' in self.target_cpu,
- 'host_cpu': detect_host_arch.HostArch(),
+ 'host_cpu': 'x64',
}
And also we should let it download in src/flutter/DEPS
: ( or maybe this is not a must after cheating in depot_tools):
flutter_engine/src/flutter$ git diff
diff --git a/DEPS b/DEPS
index c72b4d7e3d..32d7b0a97a 100644
--- a/DEPS
+++ b/DEPS
@@ -66,7 +66,7 @@ vars = {
'download_dart_sdk': True,
# Checkout Android dependencies only on platforms where we build for Android targets.
- 'download_android_deps': 'host_cpu == "x64" and (host_os == "mac" or host_os == "linux")',
+ 'download_android_deps': '(host_os == "mac" or host_os == "linux")',
# Checkout Windows dependencies only if we are building on Windows.
'download_windows_deps' : 'host_os == "win"',
We also need to disable auto update of depot_tools. depot_tools updates itself automatically when running gclient tool. To disable auto update, set the environment variable DEPOT_TOOLS_UPDATE=0 or run ./update_depot_tools_toggle.py --disable .
Do these mods and rerun gclient sync -D
it will prompt an arch change, and download the packages rightly.
The cipd will change from Chrome Infra Package Deployer (cipd 2.6.2 (infra/tools/cipd/mac-arm64@PiaJs-2JM4V3hn1ffZH7wT5QV6z5Rt77aJZaCTRfspYC))
to Chrome Infra Package Deployer (cipd 2.6.2 (infra/tools/cipd/mac-amd64@dsOLt767apUdYzHrNZ7zaQzAOZSEBHZ7ncbfUp_0zfoC))
The cpu arch change prompt:
Detected CIPD client platform change to mac-amd64.
Deleting the existing client to trigger the bootstrap...
Chrome Infra Package Deployer (cipd 2.6.2 (infra/tools/cipd/mac-amd64@dsOLt767apUdYzHrNZ7zaQzAOZSEBHZ7ncbfUp_0zfoC))
Usage: cipd [command] [arguments]
By forcing it from arm64 to x86, maybe it does two things:
- The macOS with M1 chip can run x86 program with Rosetta 2 translation, the toolchain, packages, android sdk, ndk, jdk and other binary in x86 will run normally
- Xcode will build the engine source files into the x86 target arch, this is a magical thing but it really does:
So finally it works for me to build engine from source, on MacBook Air M1 ~ 😂
Metadata
Metadata
Assignees
Labels
Type
Projects
Status
Activity
[-]Setup flutter engine environment and build engine on M1 (AppleSilicon)[/-][+]Setup flutter engine environment and build engine on M1 (AppleSilicon ARM64)[/+]--no-prebuilt-dart-sdk
#96716[-]Setup flutter engine environment and build engine on M1 (AppleSilicon ARM64)[/-][+]Setup Flutter engine environment and build engine on M1 (Apple Silicon ARM64)[/+]omarzl commentedon Mar 1, 2022
Really useful! I had the same issue when compiling the iOS engine in M1
But I only applied the workaround in
depot_tools
, since there isn't a "download iOS deps" as in AndroidAnyway here is a zip with the two patches in case anyone just wants apply them
M1FlutterEnginePatchs.zip
litang0908 commentedon Apr 5, 2022
It worked, thanks !
11 remaining items
yx-mike commentedon May 19, 2022
github-actions commentedon Jun 2, 2022
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of
flutter doctor -v
and a minimal reproduction of the issue.flar commentedon Jul 17, 2022
I know that the build is only supported using Rosetta, but the android builds don't work even with Rosetta. Is that a known issue or something that broke recently?
flar commentedon Jul 17, 2022
(Basically the android tools/ndk are not downloaded at all so trying to
gn
an android build fails early.)ColdPaleLight commentedon Jul 18, 2022
The following workaround works for me.
c.f.
https://github.com/flutter/engine/blob/b438edfd1afd9a89da3e01403d41225a34a91917/DEPS#L63
flar commentedon Jul 18, 2022
I tried that, but I then get errors trying to download various pieces:
ColdPaleLight commentedon Jul 18, 2022
I had the same errors before, when I forgot to change this line of code.
#96745 (comment)
Here is a patch made with all the changes required by depot_tools
depot_tools.patch.zip
In addition to applying the patch of depot_tools, you also need to disable its updates. Good luck :)
flar commentedon Jul 18, 2022
So, to answer my question, this doesn't build without workarounds installed in several files which means that the problem still exists (a workaround is not a fix). Perhaps these workarounds will go away if we get the issue to make this work without Rosetta fixed? Either way, this problem still exists.
flar commentedon Jul 24, 2022
Filed #108241 for the remaining work to enable Android builds on Apple Silicon.
flar commentedon Jul 27, 2022
#108241 is now closed as fixed.
I verified by creating a brand new engine directory with no modifications to my depot_tools and was able to gsync, use gn to create 3 flavors of android build (debug, profile, release) and build all 3.
We should no longer require any workarounds to build host, iOS, or Android engines on Apple Silicon Macs.