Android JNI does not find C ++ standard library header files

I follow the android-studio-jni guide and try to compile native C ++ code with gradle. Everything works fine: I can load the JNI function, write C ++ classes, compile, run and debug. And I do not need to write and maintain the make files Application.mk and Android.mk ; both of them are apparently handled by gradle implicitly. There is only one thing that I don’t understand: How to include C ++ header files from standard libraries?

I think that there must be something missing in the gradle script, but I cannot find a good link on what to add here. Here is the script:

android.ndk {
    moduleName = "hello-android-jni"

    // I tried adding the following, but nothing happens
    stl = "stlport_static"
}

And screenshots showing that all std headers are not showing.

enter image description here enter image description here

+4
2

, , :

  • .c .cpp, ndk g++ gcc.
  • stl, ​​ stl = "stlport_static", gnustl_static, system .. , , , , std::string.

  • , . , , , stl. , . , . 10 . , > Android > Sync Poroject Gradle Files.

    enter image description here

  • , ++ :

    #include <jni.h>
    #include <iostream>
    
    extern "C" {
    
    JNIEXPORT jstring JNICALL
    Java_com_yuchen_helloandroidjni_MainActivity_getMsgFromJni(JNIEnv *env, jobject instance) {
    
        // TODO
        std::string message = "Hello World From Jni";
    
        return env->NewStringUTF(message.c_str());
    }
    }
    

. , , !


:

, extern "C" { ... }. , , , :

java.lang.UnsatisfiedLinkError: void com.yuchen.helloandroidjni.getMsgFromJni() ( Java_com_yuchen_helloandroidjni_MainActivity_getMsgFromJni)

- .

+2
"your-path-to-ndk-bundle"\platforms\android-21\arch-arm\usr\include

iostream, . , - .

0

All Articles