Build problem with android studio from android-ndk-r27c to android-ndk-r29


i am a little bit lost with android setup using NDK.

Actually i use gradle plugin version 7.2.2 and Gradle version 7.4. So i should be able to use ndkDir in the build.gradle file is the setup is done in local.propertie file and -DCMAKE_C_COMPILER=C:\\android-ndk-r27c\\t

-DCMAKE_CXX_COMPILER=C:\\android-ndk-r27c\ in the build.gradle.

ans i use externalNativeBuild { cmake {path "CMakeLists.txt"} } with cmake_minimum_required(VERSION 3.3.0) and i installed the lastCmake 4.1.2 in the androidSDK/cmake directorie.

Now i have donloaded the last android-ndk-r29 and change the ndkDir in local.propertie to the new NDK and changed the DCMAKE_C_COMPILER to the new NDK.

when build my apk i got this error :

A problem occurred evaluating project ':app'.

\> NDK is not installed

Until now i alway used ndkDir to update or change NDK version using gradle version 7.4 for testing purpose. But it does not work with android-ndk-r29. I did "invalid chache" but same error.

So it look like some thing have changed and i do anderstand what and why.

thanks for help.

0
May 30 at 12:29 PM
User Avatarhterrolle
#android#cmake#android-ndk

Accepted Answer

Dont use ndk.dir in local.properties, it was deprecated.

Use this in module build.gradle:

android {
    ndkVersion "29.0.14206865"

    externalNativeBuild {
        cmake {
            path "CMakeLists.txt"
        }
    }
}

https://developer.android.com/studio/projects/configure-agp-ndk?language=agp4-1

Androids docs recommend android.ndkVersion for AGP 4.1+, with ndkPath only for special custom path cases. Android Studio installs NDKs under android-sdk/ndk/<version>. For r29 actual version is 29.0.14206865, not just r29.

You can install r29 using:

sdkmanager --install &quot;ndk;29.0.14206865&quot;

If ndk was unpacked to C:\android-ndk-r29, use ndkPath instead:

android {
    ndkPath &quot;C:/android-ndk-r29&quot;
}

Also, you should not need to pass explicitly: -DCMAKE_C_COMPILER / -DCMAKE_CXX_COMPILER, AGP/cmake should handle it for you.

User Avatarmarcinj
May 30 at 4:09 PM
0