我想编译一个开源的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安装android NDK可能会有一些问题。我能够以以下方式解决这个问题

下载android ndk from

https://developer.android.com/ndk/downloads/index.html

并放置在ndk-bundle中(安装android SDK的地方)。欲了解更多信息,请检查此屏幕。

https://app.box.com/s/dfi4h9k7v4h0tmbu3z9qnqx3d12fdejn

其他回答

更新项目gradle版本

classpath 'com.android.tools.build:gradle:3.2.1'

更新应用gradle:实现'com.android.support:appcompat-v7:28.0.0' 实现“com.android.support:设计:28.0.0”

对我来说,我认为从android studio安装android NDK可能会有一些问题。我能够以以下方式解决这个问题

下载android ndk from

https://developer.android.com/ndk/downloads/index.html

并放置在ndk-bundle中(安装android SDK的地方)。欲了解更多信息,请检查此屏幕。

https://app.box.com/s/dfi4h9k7v4h0tmbu3z9qnqx3d12fdejn

在sdk工具中删除所有的NDK。

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

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)

我所遵循的解决问题的步骤如下:

Analyze ->代码清理 从列表中选择项目,并将gradle版本更新到最新。 Build ->清洁项目 Build ->制作项目

现在,与构建相关的问题可能会被报告,比如使用编译而不是实现等。