.h
#include <jni.h>
/* Header for class com_example_ts_camerandk_NativeCamera */
#include <android/log.h>
#ifndef _Included_com_example_ts_camerandk_NativeCamera
#define _Included_com_example_ts_camerandk_NativeCamera
#ifdef __cplusplus
#define LOG_TAG "native-camera2-jni"
#define LOGI(...) __android_log_print(ANDROID_LOG_INFO,LOG_TAG,__VA_ARGS__)
#define LOGE(...) __android_log_print(ANDROID_LOG_ERROR,LOG_TAG,__VA_ARGS__)
extern "C" {
#endif
/*
* Class: com_example_ts_camerandk_NativeCamera
* Method: startPreview
* Signature: (Landroid/view/Surface;)Ljava/lang/String;
*/
JNIEXPORT jstring JNICALL Java_com_example_ts_camerandk_NativeCamera_startPreview
(JNIEnv *, jobject, jobject);
/*
* Class: com_example_ts_camerandk_NativeCamera
* Method: stopPreview
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_com_example_ts_camerandk_NativeCamera_stopPreview
(JNIEnv *, jobject);
#ifdef __cplusplus
}
#endif
#endif
.cpp
#include "com_example_ts_camerandk_NativeCamera.h"
JNIEXPORT jstring JNICALL Java_com_example_ts_camerandk_NativeCamera_startPreview(JNIEnv *env,
jclass clazz,
jobject surface){
LOGI("Java_com_example_ts_camerandk_NativeCamera_startPreview");
return env->NewStringUTF("aaaaaaaa");
}
/*
* Class: com_example_ts_camerandk_NativeCamera
* Method: stopPreview
* Signature: ()V
*/
JNIEXPORT void JNICALL Java_com_example_ts_camerandk_NativeCamera_stopPreview(JNIEnv *env,
jclass clazz){
LOGI("Java_com_example_ts_camerandk_NativeCamera_stopPreview");
}
После компиляции я получаю libnative-camera-lib.so в jniLibs, но при запуске приложения в Android Studio возникает ошибка.
AndroidRuntime: FATAL EXCEPTION: main Процесс: com.example.ts.camerandk, PID: 7413 java.lang.UnsatisfiedLinkError: Не найдена реализация для void com.example.ts.camerandk.NativeCamera.stopPreview() (пробовал Java_com_example_ts_camerandk_NativeCamera_stopPreview и Java_com_example_ts_camerandk_NativeCamera_stopPreview__) в com.example.ts.camerandk.NativeCamera.stopPreview (собственный метод)