·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");
}
编译后我在jniLibs中获得了一个libnative-camera-lib.so,但运行的应用程序在Android Studio中出错。
AndroidRuntime:FATAL EXCEPTION:主要 处理: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(原生方法)