Hello-jni sample does not work in Android Studio 2.0 Preview

I am trying to implement hello-jni sample in my project. I have Gradle 2.8 and 'com.android.tools.build:gradle-experimental:0.4.0' and using Android Studio 2.0 Preview 3b .

This is my build.gradle :

 apply plugin: 'com.android.model.application' model { android { compileSdkVersion = 23 buildToolsVersion = "23.0.2" defaultConfig.with { applicationId = "lala.lala" minSdkVersion.apiLevel = 16 targetSdkVersion.apiLevel = 23 versionCode = 1 versionName = "1.0" } } /* * native build settings */ android.ndk { moduleName = "hello-jni" // cppFlags.add("-fno-rtti") // cppFlags.add("-fno-exceptions") // ldLibs.addAll(["android", "log"]) // stl = "system" } android.productFlavors { // for detailed abiFilter descriptions, refer to "Supported ABIs" @ // https://developer.android.com/ndk/guides/abis.html#sa create("arm") { ndk.abiFilters.add("armeabi") } create("arm7") { ndk.abiFilters.add("armeabi-v7a") } create("arm8") { ndk.abiFilters.add("arm64-v8a") } create("x86") { ndk.abiFilters.add("x86") } create("x86-64") { ndk.abiFilters.add("x86_64") } create("mips") { ndk.abiFilters.add("mips") } create("mips-64") { ndk.abiFilters.add("mips64") } // To include all cpu architectures, leaves abiFilters empty create("all") } android.buildTypes { release { minifyEnabled = false //proguardFiles.add(file('proguard-rules.txt')) } } } dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) testCompile 'junit:junit:4.12' compile 'com.android.support:appcompat-v7:23.1.1' compile 'com.android.support:design:23.1.1' compile 'com.android.support:cardview-v7:23.1.1' compile 'com.android.support:recyclerview-v7:23.1.1' compile 'com.google.android.gms:play-services-ads:8.3.0' compile 'com.google.android.gms:play-services-analytics:8.3.0' compile 'com.google.android.gms:play-services-appindexing:8.3.0' } 

I created in the JNI folder hello-jni.h :

enter image description here

In some part of my code, I import this:

 static { System.loadLibrary("hello-jni"); } public static native int testMethod(); 

And when creating autocomplete hello-jni.c :

 #include "hello-jni.h" JNIEXPORT jintJNICALL Java_lala_lala_HomeScreen_testMethod(JNIEnv *env, jclass type ) { // TODO } 

Header file hello-jni.h :

 // // Created by Filip on 15.12.2015.. // #ifndef PHOTO_HELLO_JNI_H #define PHOTO_HELLO_JNI_H #endif //PHOTO_HELLO_JNI_H 

But that will not work. He is completely red:

enter image description here

What is the problem? How to solve it?

+5
source share
2 answers

This is a problem in Android studio, but only in Windows: Issue 195483
You can upgrade to Android studio 1.5.1, gradle 2.8, experimental wrapper 0.4.0 .
I tried Android Studio 2.0 beta 6, with the wrapper 0.6.0-beta5 and 0.6.0-beta6, but still does not work.

0
source

To create a sample, you can try the following steps:

  • The jni method jni Java_filsoft_photo_HomeScreen_testMethod(...) does not match the name of your package, which is lala.lala . In order for this method to be called, its signature matches the package name.
  • Try editing hello-jni.c as follows:

     #include <jni.h> #include "hello-jni.h" jint Java_lala_lala_HomeScreen_testMethod( JNIEnv* env, jclass type ) { } 
  • As for the red selected objects, with Android Studio 2.0 Preview 3b , the NDK function is not yet officially supported, and as far as I know, this is the reason. Disable Android NDK support plugin (if installed)

    Settings > Plugins > uncheck Android NDK support > restart Android Studio

+1
source

Source: https://habr.com/ru/post/1238311/


All Articles