2016-11-09 3 views
7

Я следую Create Hello-JNI With Android Studio.Не удалось найти метод ndk() для аргументов

MAC OX 10.11.5

Android Студия 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. 

Open File

+0

Я также добавил функцию JNI getMsgFromJni() и System.loadLibrary() в конец класса MainActivity. –

ответ

33

Оказывается, что этот код

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" ,

+1

Спасибо! Не могу поверить, что Google не зафиксировала свою документацию по этому вопросу: https://codelabs.developers.google.com/codelabs/android-studio-jni/index.html?index=..%2F..%2Findex#2 – kakyo

+0

Святое дерьмо. Только то. WEW. Спасибо вам, рок-азиатский парень. – ralphgabb

Смежные вопросы