Gradle sync fails with cmake "cause: executing external native build for cmake"

14,488

Solution 1

In short - Maybe the problem is in the build.gradle file imported together with the project.

try editing 'build.gradle' line 9: classpath 'com.android.tools.build:gradle:3.1.1' replace the gradle version number (in my case I replaced '3.1.1' with '3.5.0').

In more detail - I had the same issue when cloning from: https://github.com/farzaa/DracoPortedToAndroid

I did try the above (setting the ndk path) but that wasn't the problem, since the path to the ndk lib was correct. So the most probable error-cause left was some project settings imported with the cloned project.

Try comparing the "Gradle Scripts" (In the project explorer) of the imported project with a new project built in your Android Studio environment. The new project will have the correct local settings.

In my case I replaced:

classpath 'com.android.tools.build:gradle:3.1.1'

with:

classpath 'com.android.tools.build:gradle:3.5.0'

Solution 2

This could be because you have a shared library in the project which needs to be linked with the shared version of the STL. Try adding the following to your build.gradle:

android {
    defaultConfig {
        externalNativeBuild {
            cmake {
                arguments "-DANDROID_STL=c++_shared"
            }
        }
    }
}

Solution 3

to set the NDK path in android studio go to : file -> project structure -> sdk location -> android ndk location -> set path for example my ndk location on mac is /Users/username/Library/Android/sdk/ndk-bundle

Share:
14,488
e.cho
Author by

e.cho

Updated on July 20, 2022

Comments

  • e.cho
    e.cho almost 2 years

    I'm trying to build my colleagues' project in Android Studio, which requires CMake SDK to build the external c/cpp files included in the project. The problem I'm running into is despite having installed the LLDB, NDK, and CMake SDK tools through SDK manager, the gradle for the module that references cmake path fails to sync. My colleagues who already have this project installed and working haven't run into this issue, so I suspect that it has to be something in my environment setting.

    So far, I've tried uninstalling and reinstalling CMake SDK, refresh linked C++ projects, and removing the reference to the cmake path from the gradle file and adding the reference by right click the moduel -> Link C++ Project with Gradle, but none of these worked.

    When I comment out the reference to my CMakeLists.txt in the gradle, it syncs, indicating that the problem is in regards to the reference to the CMake file. I also tried commenting out library references in my CMakeLists.txt file to see if the error is occurring due to a reference in the file, but even when I comment everything out, the gradle fails to sync.

    This is what my gradle file looks like.

    externalNativeBuild {
        cmake {
            path 'src/main/cpp/CMakeLists.txt'
        }
    }
    

    When I press sync (try again) in build.gradle, the error message simply shows

    SIMPLE: Error configuring
    

    When I ignore the fact that gradle sync failed and just try to build, the error message shows as this.

    Cause: executing external native build for cmake <my_project_path>\src\main\cpp\CMakeLists.txt
    

    Edit: Added a link to the image capture of my Android Studio NDK path (C:\Users\username\AppData\Local\Android\Sdk\ndk-bundle for Windows). NDK path Capture

  • Luis Aguilar
    Luis Aguilar almost 4 years
    This worked for me, thanks. I was using classpath 'com.android.tools.build:gradle:3.1.4'