gpt4 book ai didi

java - 在 NDK 上找不到 c++ 和 java 的实现

转载 作者:行者123 更新时间:2023-11-30 02:20:04 25 4
gpt4 key购买 nike

这是我的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());
}

这里是 app/src/java/com/rtsp/RtspInterface.java

package com.rtsp;

public class RtspInterface {

public static native String helloWorld();

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

我得到:

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

这是当时的源代码树:

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

我遵循了此处的命名约定 https://developer.android.com/training/articles/perf-jni

我这样调用代码:

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

最佳答案

原来我完全忘记了为该 cpp 文件添加 CmakeLists.txt。它根本没有编译。

我做了

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)

它成功了:)

关于java - 在 NDK 上找不到 c++ 和 java 的实现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50165402/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com