如何使用 Android Gradle 插件 0.7 配置 NDK [英] How to configure NDK with Android Gradle plugin 0.7

查看:29
本文介绍了如何使用 Android Gradle 插件 0.7 配置 NDK的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

新的 Android gradle 插件 (0.7) 似乎包含对 NDK 的新支持,但在文档中几乎没有提及它(我发现的唯一参考是一个名为 ndkSanAngeles).

The new Android gradle plugin (0.7) seems to include new support for the NDK, but in the documentation there is little to no mention of it (the only reference I found is a test called ndkSanAngeles).

看起来 gradle 正在寻找 NDK,我已将其包含在我的 PATH 中.但是,构建项目失败

It looks like gradle is looking for the NDK, which I have included in my PATH. However, building the project fails with

  • 出了什么问题:任务 ':OGLTests:compileDefaultFlavorDebugNdk' 执行失败.未配置 NDK

如何在 gradle 中配置 NDK?

How can I configure the NDK in gradle?

我当前的 build.gradle 看起来像这样:

My current build.gradle looks like this:

task nativeLibsToJar(type: Zip, description: 'create a jar with native libs') {
    destinationDir file("$buildDir/native-libs")
    baseName 'native-libs'
    extension 'jar'
    from fileTree(dir: 'src/main/libs', include: '**/*.so')
    from fileTree(dir: 'src/main/libs', include: '**/gdb*')
    into 'lib/'
}

tasks.withType(JavaCompile) {
    compileTask -> compileTask.dependsOn nativeLibsToJar
}

dependencies {
    compile fileTree(dir: "$buildDir/native-libs", include: '*.jar')
}

android {
    compileSdkVersion 19
    buildToolsVersion '19.0.0'

    defaultConfig {
        minSdkVersion 14
        targetSdkVersion 19
        versionCode 1
        versionName "0.1"

    }
    buildTypes {
        release {
            runProguard false
        }
        debug {
           // jniDebugBuild true
            runProguard false
            debuggable true
        }
    }
    productFlavors {
        defaultFlavor {
            proguardFile 'proguard-rules.txt'
        }
    }
}

谢谢.

推荐答案

找到了答案.在 local.properties 文件中包含 ndk.dir=path/to/ndk 就可以了.

Found the answer. Including ndk.dir=path/to/ndk in the local.properties file did the trick.

更新:在最新版本的 Android Studio 上,您可以直接在项目结构 > SDK 位置设置该值.

Update: On the latest versions of Android Studio, you can set the value directly in the Project Structure > SDK location.

这篇关于如何使用 Android Gradle 插件 0.7 配置 NDK的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆