我想编译一个开源的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(项目:ProjectName)。然后同步你的项目

buildscript {
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:2.3.2'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

没有下载、复制或符号链接任何东西,我能够通过简单地创建一个空目录来“修复”错误,旧版本的Android Gradle插件期望删除mips工具链:

mkdir -p $ANDROID_HOME/ndk-bundle/toolchains/mips64el-linux-android/prebuilt/linux-x86_64

显然,$ANDROID_HOME指向Android SDK安装的根目录。如果是MacOS操作系统,请将上面命令中的linux-x86_64替换为darwin-x86_64。在Windows上使用Windows -x86_64。

环顾四周后,解决方案是从我的首选项中删除NDK名称。

Android Studio→首选项→系统设置→Android SDK→SDK工具→取消选择NDK→应用按钮。

在那之后,Project和Gradle编译得很好,我可以继续我的项目工作。

至于为什么会发生这种情况,我不知道,但要了解更多关于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

链接文件不适合我。

ln -s aarch64-linux-android-4.9 mips64el-linux-android
ln -s arm-linux-androideabi-4.9 mipsel-linux-android

因为还有另一个错误。

* What went wrong:
A problem occurred configuring project ':Test'.
> Expected caller to ensure valid ABI: MIPS

如果使用gradde构建,则将此添加到defaultConfig中

ndk {
    abiFilters 'armeabi-v7a','arm64-v8a','x86','x86_64'
}

如果您使用ndk-build命令,请在Application.mk中添加此命令。

APP_ABI := armeabi-v7a arm64-v8a x86 x86_64