java.lang.UnsatisfiedLinkError:找不到java.lang.String的实现com.swoop.utility.ImageStabilizer.hello()

时间:2018-05-26 12:42:08

标签: android android-ndk ndk-build

我有什么问题?请帮忙!

  

日志

java.lang.UnsatisfiedLinkError: No implementation found for java.lang.String com.swoop.utility.ImageStabilizer.hello() (tried Java_com_swoop_utility_ImageStabilizer_hello and Java_com_swoop_utility_ImageStabilizer_hello__)
    at com.swoop.utility.ImageStabilizer.hello(Native Method)
    at com.swoop.utility.ImageStabilizer.checkLibraryConnection(ImageStabilizer.java:27)
    at com.swoop.widgets.SensorImageView$FrameExtractor.onPreExecute(SensorImageView.java:121)
    at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:587)
    at android.os.AsyncTask.execute(AsyncTask.java:535)
    at com.swoop.widgets.SensorImageView.initSensors(SensorImageView.java:61)
    at com.swoop.widgets.SensorImageView.setSwoop(SensorImageView.java:52)
    at com.swoop.activity.PreviewActivity.onCreate(PreviewActivity.java:43)
    at android.app.Activity.performCreate(Activity.java:5933)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2282)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2389)
    at android.app.ActivityThread.access$900(ActivityThread.java:147)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1296)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:135)
    at android.app.ActivityThread.main(ActivityThread.java:5254)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:898)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:693)
  

gradle这个

apply plugin: 'com.android.application'

android {
compileSdkVersion 26
defaultConfig {
    applicationId "com.swoop"
    minSdkVersion 16
    targetSdkVersion 26
    versionCode 1
    versionName "1.0"
    vectorDrawables.useSupportLibrary = true
    multiDexEnabled true

    ndk{
        moduleName "ImageStabilizer"
    }
}

sourceSets.main.jni.srcDirs = []

buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
repositories {
    maven { url "https://jitpack.io" }
    mavenCentral()
}

aaptOptions {
    cruncherEnabled = false
}

}

dependencies {
...
...
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation project(':libraries:opencv')
}
}
  

Android.mk

LOCAL_PATH := $(call my-dir)

CVROOT := D:/Rajesh/Downloads/OpenCV-android-sdk/sdk/native/jni

include $(CLEAR_VARS)
OPENCV_INSTALL_MODULES:=on
OPENCV_LIB_TYPE:=STATIC
include $(CVROOT)/OpenCV.mk

LOCAL_MODULE += ImageStabilizer

LOCAL_C_INCLUDES += ImageStabilizer.h
LOCAL_SRC_FILES += main.cpp

LOCAL_CFLAGS += -std=c++11 -frtti -fexceptions -fopenmp -w
LOCAL_LDLIBS += -llog -L$(SYSROOT)/usr/lib
LOCAL_LDFLAGS += -fopenmp

include $(BUILD_SHARED_LIBRARY)
  

的main.cpp

#include "com_swoop_utility_ImageStabilizer.h"

#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/features2d/features2d.hpp>
#include <android/log.h>
#include <opencv2/video/tracking.hpp>

using namespace std;
using namespace cv;

#define  LOG_TAG    "JNI_LOG"
#define  ALOG(...)  __android_log_print(ANDROID_LOG_INFO,LOG_TAG,__VA_ARGS__)

extern "C"
{
    JNIEXPORT jstring JNICALL Java_com_swoop_utility_ImageStabilizer_hello
        (JNIEnv *env, jobject obj){
    return env->NewStringUTF("Hello from JNI");
    }
}
  

ImageStabilizer类

public class ImageStabilizer {
static {
    try {
        System.loadLibrary("ImageStabilizer");
    } catch (UnsatisfiedLinkError use) {
        Log.e("JNI", "WARNING: Could not load native library");
    }
}

public native String hello();

public native int getGrayImages(long[] orignalMats, long[] resultMats, int numOfImages);

public native int getFeatrueExtractedImages(long[] orignalMats, long[] resultMats, int numOfImages);

public native int getMatchedFeatureImages(long[] orignalMats, long[] resultMats, int numOfImages);

public native int getStabilizedImages(long[] originalMats, long[] resultMats, int numOfImages);

public String checkLibraryConnection() {
    return hello();
}
}

0 个答案:

没有答案