简体   繁体   中英

No implementation found for c++ and java on NDK

Here's my app/src/main/cpp/rtspinterface.cpp

#include <jni.h>
#include <android/log.h>
#include <string>

extern "C" JNIEXPORT jstring JNICALL Java_com_rtsp_RtspInterface_helloWorld(
    JNIEnv *env, jobject thiz) {

   return (*env)->NewStringUTF(env, "Hello from JNI !".c_str());
}

and here is app/src/java/com/rtsp/RtspInterface.java

package com.rtsp;

public class RtspInterface {

    public static native String helloWorld();

    static {
        System.loadLibrary("myRtspClient");
    }
}

I'm getting:

no implementation found for Java.lang.String.com.rtsp.RtspInterface.helloWorld() (tried Java_com_rtsp_RtspInterface_helloWorld and Java_com_rtsp_RtspInterface_helloWorld__)

Here is the source tree at the exact moment:

https://github.com/lucaszanella/jscam/tree/8da9d546cbf6ad7cf6551010dbb42e8117d1d72d/src/jscam/android/app/src/main

I followed the naming conventions from here https://developer.android.com/training/articles/perf-jni

I'm calling the code like this:

Log.v("test", RtspInterface.helloWorld());

Turns out I completely forgot to add a CmakeLists.txt for that cpp file. It simply wasn't compiling.

I did

cmake_minimum_required(VERSION 3.4.1)

add_subdirectory("../../../../../myRtspClient/myRtspClient" myRtspClient_bin)

add_library(rtspInterface SHARED rtspInterface.cpp)

target_link_libraries(rtspInterface android log)

and it worked :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM