android studio中为gradle指定cmake版本

Android Studio相当于是Intellij基础上写了一个AS插件,这个插件使用gradle作为构建系统,因此构建出现问题先考虑gradle的文档。

gradle可以使用native build system,例如cmake。gradle中使用cmake时可以指定cmake版本,官方文档:https://google.github.io/android-gradle-dsl/current/com.android.build.gradle.internal.dsl.CmakeOptions.html

使用情景:我在系统中装了一个cmake3.13.4,发现android studio的sdk会去自行为ndk工程下载cmake3.6。我只想用cmake3.13.4。

具体设置:

方法1:<项目根目录>/app/build.gradle:

    externalNativeBuild {
        cmake {
            ...
            // Specifies the version of CMake the Android plugin should use. You need to
            // include the path to the CMake binary of this version to your PATH
            // environmental variable.
            version "3.13.4"
        }
    }

方法2:<项目根目录>/local.properties:

cmake.dir=E:\soft\cmake-3.13.4-win64-x64

总结很傻就是了,只能一个一个项目的配置,不能全局的配置。做AS的大佬们有讨论过:https://groups.google.com/forum/#!topic/android-ndk/3WV5iNjISKY ,甩锅给gradle项目,2333.

原文地址:https://www.cnblogs.com/zjutzz/p/10814996.html