使用CMake构建Gradle时版本获取失败问题求助
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, likeC:\cmake-3.10.1, then update thecmake.dirline inlocal.propertiesto match the new path:cmake.dir=C:\cmake-3.10.1Verify the CMake executable exists
Double-check thatC:\Users\Mujtaba Faizi\Downloads\cmake-3.10.1\bin\cmake.exeactually 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 cleanThen restart Android Studio and try building your project again.
Confirm Android Studio is using the correct CMake path
Go toFile > Project Structure > SDK Locationand look for theCMakefield. Make sure it points to the same directory ascmake.dirinlocal.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 yourlocal.propertiespath—even a single wrong character can break the detection. For example, ensure the directory name is exactlycmake-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

