我想编译一个开源的android项目(Netguard)使用gradel (gradlew清洁构建)但我遇到了这个错误:

A problem occurred configuring project ':app'.
> Exception thrown while executing model rule: NdkComponentModelPlugin.Rules#cre
ateToolchains
   > No toolchains found in the NDK toolchains folder for ABI with prefix: llvm

我搜索了一下,但没有发现任何有用的东西。这是主要的build.gradle:

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle-experimental:0.6.0-alpha1'
    }
}
allprojects {
    repositories {
        jcenter()
    }
}
task clean(type: Delete) {
    delete rootProject.buildDir
}

这是构造。应用项目的Gradle:

apply plugin: 'com.android.model.application'

model {
    android {
        compileSdkVersion = 23
        buildToolsVersion = "23.0.2"

        defaultConfig.with {
            applicationId = "eu.faircode.netguard"
            minSdkVersion.apiLevel = 21
            targetSdkVersion.apiLevel = 23
            versionCode = 2016011801
            versionName = "0.76"
            archivesBaseName = "NetGuard-v$versionName-$versionCode"
        }
    }
    android.ndk {
        moduleName = "netguard"
        toolchain = "clang"
        ldLibs.add("log")
    }
    android.sources {
        main {
            jni {
                source {
                    srcDir "src/main/jni/netguard"
                }
                exportedHeaders {
                }
            }
        }
    }
    android.buildTypes {
        release {
            minifyEnabled = true
            proguardFiles.add(file('proguard-rules.pro'))
            ndk.with {
                debuggable = true
            }
        }
    }
    android.buildTypes {
        debug {
            ndk.with {
                debuggable = true
            }
        }
    }
    android.productFlavors {
        create("all") {
        }
    }
}

dependencies {


compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:23.1.+'
    compile 'com.android.support:recyclerview-v7:23.1.+'
    compile 'com.squareup.picasso:picasso:2.5.+'
}

我使用gradle-2.9-all和android-ndk-r10e。我不知道我是否应该提到其他东西,所以如果你需要任何信息,请评论。


当前回答

在我的案例中,一些支持文件在新的NDK版本“23.0.7599858”中丢失了,所以我将版本降级为“22.1.7171670”。你也可以在"../Sdk/ NDK "上找到所有下载的NDK版本。

android {
compileSdkVersion 30
buildToolsVersion "29.0.2"

defaultConfig {
    ...
    ...
    ndkVersion "22.1.7171670"
}

其他回答

如果你使用Ionic 3,从android studio sdk工具中删除ndk。

我通过重新安装NDK解决了这个问题。

我通过在SDK-Tools中卸载NDK来修复这个错误。 因此,如果您不需要NDK,请卸载它。

首先,尝试更新ndk版本 https://developer.android.com/ndk/downloads/

如果这还不行,你可以试试下面的方法:

Create a folder Go to the Sdk\ndk-bundle\toolchains folder (in my case its C:\Users\USER\AppData\Local\Android\Sdk\ndk-bundle\toolchains; you can find yours under File->project structure->SDK location in you android studio) and create a folder with the name that's shown as missing in the error for eg: if the error is Gradle sync failed: No toolchains found in the NDK toolchains folder for ABI with prefix: mipsel-linux-android Then create a folder with name mipsel-linux-android Include content Go to the Sdk\ndk-bundle\toolchains folder again and open any folder that's already in it. For example:Sdk\ndk-bundle\toolchains\aarch64-linux-android-4.9 (in mycase C:\Users\USER\AppData\Local\Android\Sdk\ndk-bundle\toolchains\aarch64-linux-android-4.9) copy the prebuilt folder in it to the folder we created in the last step

打开你的包。Gradle文件和升级以下两个类路径的版本:

classpath 'com.android.tools.build:gradle:3.2.1'
classpath 'com.google.gms:google-services:4.2.0'

然后同步,在得到一个对话框更新Gradle版本,然后点击该链接,等待下载所有所需的更新。