代码之家  ›  专栏  ›  技术社区  ›  John F Donigan

Android Studio 3.1.2-无法运行C++子例程“找不到Java.lang.String的实现…”

  •  1
  • John F Donigan  · 技术社区  · 7 年前

    我的代码可以编译,但当我调用C++子例程时,应用程序会因一个不满意的链接错误而终止。

    在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);
    

    在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)
    

    我在当地四处打听,运气不好。我错过了什么?谢谢

    1 回复  |  直到 7 年前
        1
  •  1
  •   John F Donigan    7 年前

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