如何在 Gradle 中设置 NDK 库路径?

How to set NDK lib path in Gradle?

我正在使用 ebookdroid & MuPDF CPP 文件开发 PDF 查看器应用程序。 Gradle 中的 NDK 集成有很多问题。我看了很多答案,但他们没有解决我的问题。

Gradle 给我以下错误消息:

Error:Execution failed for task ':app:compileDebugNdk'.
Error: Your project contains C++ files but it is not using a supported native build system.
Consider using CMake or ndk-build integration with the stable Android Gradle plugin:
    https://developer.android.com/studio/projects/add-native-code.html
    or use the experimental plugin:
    http://tools.android.com/tech-docs/new-build-system/gradle-experimental.

编辑您的 build.gradle,添加 defaultConfig.externalNativeBuild.ndkBuildexternalNativeBuild.ndkBuildsourceSet.main.jni.srcDir 选项。请参阅下面的评论。

android {
        compileSdkVersion 22
        buildToolsVersion "27.0.0"

        defaultConfig {
            minSdkVersion 18
            targetSdkVersion 22
            versionCode 1
            versionName "1.0"

            //add arguments passed to ndkBuild 
            externalNativeBuild {
                ndkBuild {
                    arguments "NDK_TOOLCHAIN_VERSION=clang", "APP_SHORT_COMMANDS=true", "APP_ALLOW_MISSING_DEPS=true"
                    arguments "-j" + Runtime.runtime.availableProcessors()
                    cFlags "-fexceptions"
                }
            }

            ndk {
                abiFilters "armeabi-v7a"
            }
        }

        //specify jni source file path
        sourceSets.main {
            java.srcDir "src"
            res.srcDir "res"
            jni.srcDir "jni"
        }


        buildTypes {
            debug {
                debuggable true
                jniDebuggable true
            }
        }

        //specify makefile / CMake file
        externalNativeBuild {
            ndkBuild {
                path 'jni/Android.mk'
            }
        }
    }