47

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 :)

GitHub Issue Tracker

2 Answers 2

109

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

#!/bin/sh
DIR="$(cd "$(dirname "$0")" && pwd)"
$DIR/build/ndk-build "$@"

to

#!/bin/sh
DIR="$(cd "$(dirname "$0")" && pwd)"
arch -x86_64 /bin/bash $DIR/build/ndk-build "$@"

Reference Link

13
  • 2
    worked like a charm Oct 13, 2021 at 16:51
  • 3
    If you don't find the Library folder in /Users/{username}/. Press Cmd + Shift +"." to show hidden folders Dec 3, 2021 at 6:57
  • 1
    I tried this but then I'm getting "Cause: error=1, Operation not permitted" while building project and build failes Mar 29, 2022 at 8:26
  • 1
    same error after re-installing Mar 30, 2022 at 6:21
  • 2
    I figured out that TextEdit messes up the file and corrupts it, so better edit the file directly in Android Studio or VS Code or any editor of your choice other than TextEdit Mar 30, 2022 at 9:59
32

To solve this on a Apple Silicon M1 I found three options

A

Use NDK 24

android {
    ndkVersion "24.0.8215888"
    ...
}

You can install it with

echo "y" | sudo ${ANDROID_HOME}/tools/bin/sdkmanager --install 'ndk;24.0.8215888'

or

echo "y" | sudo ${ANDROID_HOME}/sdk/cmdline-tools/latest/bin/sdkmanager --install 'ndk;24.0.8215888'

Depending what where sdkmanager is located enter image description here

B

Change your ndk-build to use Rosetta x86. Search for your installed ndk with

find ~ -name ndk-build 2>/dev/null

eg

vi ~/Library/Android/sdk/ndk/22.1.7171670/ndk-build

and change

DIR="$(cd "$(dirname "$0")" && pwd)"
$DIR/build/ndk-build "$@"

to

DIR="$(cd "$(dirname "$0")" && pwd)"
arch -x86_64 /bin/bash $DIR/build/ndk-build "$@"

enter image description here

C

convert your ndk-build into a cmake build

4
  • 1
    "$@ is missing closing quotations at the end Nov 5, 2021 at 20:08
  • 1
    A for OS X: #: sudo [AndroidSDK folder]/cmdline-tools/latest/bin/sdkmanager --install 'ndk;24.0.7956693' --channel=3. The latest cmdline-tools should be installed via AS package manager.
    – oxied
    Jan 26, 2022 at 15:36
  • See my answer, point A @oxied
    – hannes ach
    Jan 26, 2022 at 15:57
  • 1
    Your A doesn't work for me. My A — works.
    – oxied
    Jan 27, 2022 at 16:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.