skip to Main Content

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


  1. Chosen as BEST ANSWER

    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


  2. 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

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search