You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用CMake构建Gradle时版本获取失败问题求助

解决CMake版本检测失败的问题

Hey there, I know this error has been bugging you for a while—let's break down why Gradle can't detect your CMake 3.10.1 installation even though you've set up the paths, and fix it step by step.

First, let's recap your current configs for reference:

build.gradle 配置

apply plugin: 'com.android.application'
android {
    compileSdkVersion 26
    defaultConfig {
        applicationId "com.example.mujtaba.basicai"
        minSdkVersion 21
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    sourceSets {
        main {
            jni.srcDirs = ['src/main/jni', 'src/main/jniLibs/', 'src/main/jniLibs/armeabi-v7a']
        }
    }
    externalNativeBuild {
        cmake {
            version "3.10.1"
            path 'CMakeLists.txt'
        }
    }
}
dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    implementation 'com.android.support:appcompat-v7:26.1.0'
    implementation 'com.android.support:design:26.1.0'
    implementation 'com.android.support.constraint:constraint-layout:1.0.2'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.1'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
    compile files('libs/libandroid_tensorflow_inference_java.jar')
    compile 'com.flurgle:camerakit:0.9.13' //for camera access purposes
}

local.properties 配置

cmake.dir=C:\Users\Mujtaba Faizi\Downloads\cmake-3.10.1
ndk.dir=C:\Users\Mujtaba Faizi\AppData\Local\Android\Sdk\ndk-bundle
sdk.dir=C:\Users\Mujtaba Faizi\AppData\Local\Android\Sdk

Now, here are the most likely fixes for your error:

  • Fix the space in your path
    The biggest red flag here is the space in your username (Mujtaba Faizi). Windows paths with spaces often cause issues with build tools like Gradle and CMake. Try moving your CMake installation to a directory without spaces, like C:\cmake-3.10.1, then update the cmake.dir line in local.properties to match the new path:

    cmake.dir=C:\cmake-3.10.1
    
  • Verify the CMake executable exists
    Double-check that C:\Users\Mujtaba Faizi\Downloads\cmake-3.10.1\bin\cmake.exe actually exists. Sometimes incomplete downloads or corrupted archives can lead to missing files. If it's missing, re-download CMake 3.10.1 and extract it again.

  • Clear Gradle cache and rebuild
    Gradle might be holding onto old cache data that's conflicting with your current setup. Run this command in your project root to clean the cache:

    ./gradlew clean
    

    Then restart Android Studio and try building your project again.

  • Confirm Android Studio is using the correct CMake path
    Go to File > Project Structure > SDK Location and look for the CMake field. Make sure it points to the same directory as cmake.dir in local.properties. Sometimes Android Studio auto-detects a different version, so manually setting it here can resolve mismatches.

  • Check for typos in paths
    Double-check that there are no typos in your local.properties path—even a single wrong character can break the detection. For example, ensure the directory name is exactly cmake-3.10.1 (no extra spaces or misspellings).

Give these steps a try, and I bet one of them will get your build working again!

内容的提问来源于stack exchange,提问作者Mujtaba Faizi

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 07:36:39