Skip to content

[android] Build on mac M1 #35

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion PluginSource/projects/Android/jni/Application.mk
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
APP_ABI := armeabi-v7a arm64-v8a x86 x86_64
APP_PLATFORM := android-9
APP_STL := gnustl_static
APP_STL := c++_static
APP_CPPFLAGS += -std=c++11
NDK_TOOLCHAIN_VERSION := clang
35 changes: 35 additions & 0 deletions PluginSource/projects/Android/jni/make_apple_M1.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/bash

set -e

patch_ndk_on_apple_m1() {
os=$(uname -s)
arch=$(uname -m)

if [ $os == "Darwin" -a $arch == "arm64" ]; then
# Fix for building with NDK on Apple Silicon
# https://stackoverflow.com/questions/69541831/unknown-host-cpu-architecture-arm64-android-ndk-siliconm1-apple-macbook-pro
if [ ! -f $UNITY_NDK/ndk-build.old ]; then
cp $UNITY_NDK/ndk-build $UNITY_NDK/ndk-build.old
fi
echo '#!/bin/sh' > $UNITY_NDK/ndk-build
echo 'DIR="$(cd "$(dirname "$0")" && pwd)"' >> $UNITY_NDK/ndk-build
echo 'arch -x86_64 /bin/bash $DIR/build/ndk-build "$@"' >> $UNITY_NDK/ndk-build
fi
}

main() {

patch_ndk_on_apple_m1

# set UNITY_NDK environment variable to NDK installation used by Unity
# i. e. /Applications/Unity/Hub/Editor/2022.1.24f1/PlaybackEngines/AndroidPlayer/NDK
echo "Using UNITY_NDK: $UNITY_NDK"

# https://developer.android.com/ndk/guides/ndk-build
export NDK_PROJECT_PATH=$(cd ../ && pwd)
echo "Using NDK_PROJECT_PATH: $NDK_PROJECT_PATH"
$UNITY_NDK/ndk-build
}

main