Android Studio 3.1.2 - 无法运行C++子例程"No implementation found for Java.lang.String..."

Android Studio 3.1.2 - Can't run a C++ subroutine "No implementation found for Java.lang.String..."

本文关键字:implementation No found for String lang Java 子例程 C++ Studio 运行      更新时间:2023-10-16

我的代码可以编译,但是当我调用C++子例程时,应用程序会因不满意的LinkError而死亡。

在CMakeLists中.txt:

add_library( # Sets the name of the library.
native-lib
# Sets the library as a shared library.
SHARED
# Provides a relative path to your source file(s).
src/main/cpp/crlTCheckkey.cpp)

在选项卡 1.java 中:

package com.labyrinthsys.crltext;
String statusString;
String keyPath;
statusString = crlTCheckkey(keyPath);
...
public native String crlTCheckkey(String keyPath);

In crlTCheckkey.cpp:

#include <jni.h>
#include <string>
using namespace std;
extern "C" JNIEXPORT jstring
JNICALL
Java_com_labyrinthsys_crltext_Tab1_crlTCheckkey(
JNIEnv *env,
jobject, /* this */
jstring keyFilePath) {

我得到的错误是:

java.lang.UnsatisfiedLinkError: No implementation found for java.lang.String com.labyrinthsys.crltext.Tab1.crlTCheckkey(java.lang.String) (tried Java_com_labyrinthsys_crltext_Tab1_crlTCheckkey and Java_com_labyrinthsys_crltext_Tab1_crlTCheckkey__Ljava_lang_String_2)
at com.labyrinthsys.crltext.Tab1.crlTCheckkey(Native Method)
at com.labyrinthsys.crltext.Tab1.onClick(Tab1.java:118)

我在当地打听过,但没有运气。我错过了什么?谢谢!

这很烦人,但我从构建中完全删除了有问题的 cpp 文件,然后从头开始再次引入它,不知何故它现在可以工作了。