我想编译一个开源的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。我不知道我是否应该提到其他东西,所以如果你需要任何信息,请评论。


当前回答

在android studio编译一个项目时,我偶尔会遇到:

错误:在ABI with的NDK工具链文件夹中没有找到工具链 前缀:arm-linux-androideabi / llvm

可能是更新相关组件导致。解决方案是Android studio (Tools -> Android -> SDK Manager)。 选择ndk项并删除它。如果程序需要它,可以重新安装它。这将确保文件夹位置是正确的,不会有这样的问题。

其他回答

使用这个选项过滤出希望Abi前缀的使用:

android {
    defaultConfig {
        ndk {
            abiFilters 'arm64-v8a', 'x86_64', ...
        }
    }
}

升级你的Gradle插件

com.android.tools.build: gradle: 3.1.4 升级gradle的wraperproperties - 4.4 - all.zip distributionUrl = https://services.gradle.org/distributions/gradle

循序渐进:

1)打开旧版本的NDK页面:

https://developer.android.com/ndk/downloads/older_releases

2)同意本条款:

3)下载旧版本的NDK(例如16b):

4)打开工具链目录。

5)将你需要的文件从toolchains文件夹下载压缩文件到你的toolchains文件夹:

6)重建项目:


UPD 2018年9月30日: 在我自己的情况下,我使用Android NDK Revision r16b来修复这个错误。所以我用这个版本来展示这个例子。 但最好使用Android NDK,修订版r17c(2018年6月)。这是最后一个,支持mips(来自Weekend评论的合理建议)。

我尝试用以下方法来解决这个问题:

Stay Android build tools version the same with gradle version. For example:if you use the build tools version is 3.3.0,your gradle version must be 4.10.1.You can reference by the link https://developer.android.com/studio/releases/gradle-plugin and chagne your build tools & gradle version in your AS(File->Project Structure->Project) If method1 don't work,you can custom your ndk toolchains version to solve the problem :like download ndk18 or ndk16 , setting the ndk path is your AS(File->Project Structure->SDK Location->Android NDK Location)

从IntellJ IDEA卸载旧版本SDK ->外观->系统设置-> Android SDK -> SDK平台。

安装新的Android SDK版本,无论你想要什么版本。

在安装新的SDK时,取消选中SDK工具下的NDK复选框。