UnsatisfiedLinkError:未找到int的实现

时间:2019-10-08 14:19:12

标签: android android-ndk

尽管方法命名似乎是正确的,但IDE会引发没有实现的错误。

我已经检查了我的c ++代码中的拼写。

尝试使用本机方法时会发生此错误:

java.lang.UnsatisfiedLinkError: No implementation found for int pl.mike.LinkVideoCore.sysinit(java.lang.String) (tried Java_pl_mike_LinkVideoCore_sysinit and Java_pl_mike_LinkVideoCore_sysinit__Ljava_lang_String_2)
        at pl.mike.LinkVideoCore.sysinit(Native Method)
        at pl.mike.MainActivity.onCreate(MainActivity.java:20)

MainActivity看起来像这样:

linkStream = new LinkVideoCore();
        linkStream.sysinit("192.168.11.123");

这是LinkVideoCore:

    static {
        System.loadLibrary("mp3lame");
        System.loadLibrary("linkcardplayer");
        System.loadLibrary("linkcardsdk");
    }

    public native int sysinit(String pIP);

这是我配置Android.mk的方式:

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)
LOCAL_MODULE            := mp3lame
LOCAL_SRC_FILES         := lib/$(TARGET_ARCH_ABI)/libmp3lame.so
include $(PREBUILT_SHARED_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE            := linkcardplayer
LOCAL_SRC_FILES         := lib/$(TARGET_ARCH_ABI)/liblinkcardplayer.so
include $(PREBUILT_SHARED_LIBRARY)


include $(CLEAR_VARS)

LOCAL_MODULE := linkcardsdk

LOCAL_C_INCLUDES += $(LOCAL_PATH) 

LOCAL_EXPORT_C_INCLUDES:= $(LOCAL_PATH)/sdk.h

LOCAL_SRC_FILES := \
    sdk-jni-demo.c 

LOCAL_LDLIBS  +=  -Wl,--gc-sections -llog -lz -ldl -ljnigraphics
LOCAL_SHARED_LIBRARIES := mp3lame linkcardplayer

include $(BUILD_SHARED_LIBRARY)
#include $(BUILD_STATIC_LIBRARY)

Application.mk:

APP_ABI :=armeabi-v7a
APP_PLATFORM := android-17
APP_STL := c++_static
TARGET_ARCH_ABI :=armeabi-v7a

sdk-jni-demo.c:

jint  __attribute__ ((visibility ("default"))) Java_pl_mike_LinkVideoCore_sysinit(JNIEnv *env, jobject thiz,jstring jname)
{
    int ret = 0;
    const char * pRemoteIP  = (*env)->GetStringUTFChars(env,jname, NULL);   //
    LOGV("[%s-%d]: \n", __FUNCTION__, __LINE__);
    SDK_Entry();
    ret = SDK_Connect(pRemoteIP);
    (*env)->ReleaseStringUTFChars(env,jname, pRemoteIP);
    return ret;
}

build.gradle:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 29
    buildToolsVersion '28.0.3'
    defaultConfig {
        applicationId "pl.mike.xeyepoc"
        minSdkVersion 14
        targetSdkVersion 29
        versionCode 5
        versionName "5.0"
        ndk {
            abiFilters 'x86', 'x86_64', 'armeabi', 'armeabi-v7a', 'arm64-v8a'
        }
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }

    sourceSets{
        main{
            jni.srcDirs = []
            jniLibs.srcDirs = ['src/main/libs']
        }
    }
}

dependencies {
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
}

gradle.properties:

android.useDeprecatedNdk=true

1 个答案:

答案 0 :(得分:-1)

制作arm64-v8a,如果您使用的是模拟器,请在真实设备上尝试。