Solved: M1 Unknown host CPU architecture: arm64
On M1 machine, when we build android application, it report this error:
On M1 machine, when we build android application, it report this error:Unknown host CPU architecture: arm64
And I find the answer from this website: Unknown host CPU architecture: arm64 , Android NDK SiliconM1 Apple MacBook Pro
The problem we encounter is because our project, use the ndk version 21.0.6113669
, and we solved the problem by updating the ndk-build
under ndk folder.
Which ndk version the project is using
In the build.gradle.kts
file, there is a setting like this: ndkVersion = "21.0.6113669"
, another place to find the ndk version we are using is open the Project Structure
(⌘+;
) window, select Modules on the left, we can see the ndk version the project are using on the right.
Update file ndk-build
After we get the ndk version, we can navigate to ndk folder at ~/Library/Android/sdk/ndk/<ndk version>
.
Change the last line of ndk-build
file.
# $DIR/build/ndk-build "$@"
Another try
I think we can also upgrade the ndk version to the latest, which is 24.0.8215888
, if so, the project will work on both M1 and Mac with Intell chip, but after upgrade the ndk, I find that some third party libraries will build failed, so I think for us the best solution is update the ndk-build
file.