找不到参数的方法ndk()

Chi*_*HAN 15 android-ndk

我正在关注使用Android Studio创建Hello-JNI.

MAC OX 10.11.5

Android Studio 2.2稳定

java版本:1.7.0_79

gradle这个-2.14.1

这是我的app.gradle:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.1"
    defaultConfig {
        applicationId "com.chenql.helloandroidjni"
        minSdkVersion 14
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    ndk {
        moduleName "hello-android-jni"
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:23.3.0'
    compile 'com.android.support:design:23.3.0'
    testCompile 'junit:junit:4.12'
}
Run Code Online (Sandbox Code Playgroud)

这是错误: 错误消息

Error:(20, 0) Could not find method ndk() for arguments [build_13jh6qtzl4f08f8c1of3mvsys$_run_closure1$_closure5@5b127949] on project ':app' of type org.gradle.api.Project.
Run Code Online (Sandbox Code Playgroud)

打开文件

Chi*_*HAN 54

原来这个代码

ndk {
    moduleName "hello-android-jni"
    }
Run Code Online (Sandbox Code Playgroud)

应放在"defaultConfig"块下:

defaultConfig {
    applicationId "com.chenql.helloandroidjni"
    minSdkVersion 22
    targetSdkVersion 23
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

    ndk {
        moduleName "hello-android-jni"
    }
}
Run Code Online (Sandbox Code Playgroud)

在"buildTypes"块之后的instaed.

  • 谢谢!无法相信谷歌没有修改他们的文档:https://codelabs.developers.google.com/codelabs/android-studio-jni/index.html?index =..%2F..%2Findex#2 (3认同)
  • 谢谢,你帮了我很多! (2认同)