I’ve got a project that is working fine in windows os but when I switched my laptop and opened an existing project in MacBook Pro M1. I’m unable to run an existing android project in MacBook pro M1. first I was getting
Execution failed for task ‘:app:kaptDevDebugKotlin’. > A failure
occurred while executing
org.jetbrains.kotlin.gradle.internal.KaptExecution >
java.lang.reflect.InvocationTargetException (no error message)
this error was due to the Room database I applied a fix that was adding below library before Room database and also changed my JDK location from file structure from JRE to JDK.
kapt "org.xerial:sqlite-jdbc:3.34.0"
//Room components
kapt "org.xerial:sqlite-jdbc:3.34.0"
implementation "androidx.room:room-ktx:$rootProject.roomVersion"
kapt "androidx.room:room-compiler:$rootProject.roomVersion"
androidTestImplementation "androidx.room:room-testing:$rootProject.roomVersion"
after that now I’m getting an issue which is Unknown host CPU architecture: arm64
there is an SDK in my project that is using this below line.
android {
externalNativeBuild {
ndkBuild {
path 'Android.mk'
}
}
ndkVersion '21.4.7075529'
}
App Gradle
externalNativeBuild {
cmake {
path "src/main/cpp/CMakeLists.txt"
version "3.18.1"
//version "3.10.2"
}
}
[CXX1405] error when building with ndkBuild using
/Users/mac/Desktop/Consumer-Android/ime/dictionaries/jnidictionaryv2/Android.mk:
Build command failed. Error while executing process
/Users/mac/Library/Android/sdk/ndk/21.4.7075529/ndk-build with
arguments {NDK_PROJECT_PATH=null
APP_BUILD_SCRIPT=/Users/mac/Desktop/Consumer-Android/ime/dictionaries/jnidictionaryv2/Android.mk
APP_ABI=arm64-v8a NDK_ALL_ABIS=arm64-v8a NDK_DEBUG=1
APP_PLATFORM=android-21
NDK_OUT=/Users/mac/Desktop/Consumer-Android/ime/dictionaries/jnidictionaryv2/build/intermediates/cxx/Debug/4k4s2lc6/obj
NDK_LIBS_OUT=/Users/mac/Desktop/Consumer-Android/ime/dictionaries/jnidictionaryv2/build/intermediates/cxx/Debug/4k4s2lc6/lib
APP_SHORT_COMMANDS=false LOCAL_SHORT_COMMANDS=false -B -n} ERROR:
Unknown host CPU architecture: arm64
which is causing this issue and whenever I comment on this line
path ‘Android.mk’
it starts working fine, is there any way around which will help me run this project with this piece of code without getting this NDK issue?
Update – It seems that Room got fixed in the latest updates, Therefore you may consider updating Room to the latest version (2.3.0-alpha01 / 2.4.0-alpha03 or above)
use ndkVersion "24.0.8215888" update ndk to this version and no need to edit any script 🙂
2
Answers
solved this issue.
Finder -> Go To Folder(/Users/mac/Library/Android/sdk/ndk/21.4.7075529) -> now edit ndk-build open it in text editor and paste below code script and re-run your project.
from
to
Reference Link
To solve this on a Apple Silicon M1 I found three options
A
Use NDK 24
You can install it with
or
Depending what where
sdkmanager
is locatedB
Change your
ndk-build
to use Rosetta x86. Search for your installed ndk witheg
and change
to
C
convert your
ndk-build
into acmake
build