无法为参数找到方法ndk()
问题描述:
我正在关注Create Hello-JNI With Android Studio。无法为参数找到方法ndk()
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'
}
以下是错误: The Error Message
Error:(20, 0) Could not find method ndk() for arguments [[email protected]] on project ':app' of type org.gradle.api.Project.
打开文件
答
事实证明,这种代码
ndk {
moduleName "hello-android-jni"
}
应该在 “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"
}
}
的instaed后 “buildTypes” 块。
我还将JNI函数getMsgFromJni()和System.loadLibrary()添加到了MainActivity类的末尾。 –