java so jnienv_完美起航-JNI初步(五)jnindk一个.so文件依赖另一个.so文件的写法

注意:本文是在ndk环境下编写

1.写native类声明native方法

package com.godv.audiosuc;

public class NativePlayers {

static{

System.loadLibrary("JNI_ANDROID_AUDIOS");

System.loadLibrary("JNI_ANDROID_TEST");

}

//native方法

public static native int show(String url);

public static native String shutDown();

}

2.java-h 生成对应的jni 头文件

/* DO NOT EDIT THIS FILE - it is machine generated */

#include /* Header for class com_godv_audiosuc_NativePlayers */

#ifndef _Included_com_godv_audiosuc_NativePlayers

#define _Included_com_godv_audiosuc_NativePlayers

#ifdef __cplusplus

extern "C" {

#endif

/*

* Class: com_godv_audiosuc_NativePlayers

* Method: show

* Signature: (Ljava/lang/String;)I

*/

JNIEXPORT jint JNICALL Java_com_godv_audiosuc_NativePlayers_show

(JNIEnv *, jclass, jstring);

/*

* Class: com_godv_audiosuc_NativePlayers

* Method: shutDown

* Signature: ()Ljava/lang/String;

*/

JNIEXPORT jstring JNICALL Java_com_godv_audiosuc_NativePlayers_shutDown

(JNIEnv *, jclass);

#ifdef __cplusplus

}

#endif

#endif

3.写实现类调用另一个cpp中的方法 (这里称这个类为  方法类)

#include "NativePlayers.h"

#include #include #include "Test.h"

JNIEXPORT jint JNICALL Java_com_godv_audiosuc_NativePlayers_show

(JNIEnv * env, jclass clazz, jstring jstr)

{

Test t;

return t.play();

}

JNIEXPORT jstring JNICALL Java_com_godv_audiosuc_NativePlayers_shutDown

(JNIEnv * env, jclass clazz)

{

jstring str = env->NewStringUTF("Im godv !");

return str;

}

3.1.方法类c++

#ifndef FFMPEG_TEST_H

#define FFMPEG_TEST_H

#include #include class Test{

public:

int play();

};

#endif //FFMPEG_TEST_H

#include "Test.h"

int Test::play() {

return 0;

}

4.首先将方法类封装成.so动态库

4.1android.mk文件

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE := JNI_ANDROID_TEST

LOCAL_SRC_FILES := Test.cpp

include $(BUILD_SHARED_LIBRARY)

4.2ndk-build 生成 libJNI_ANDROID_TEST.so

5.写生成jni .so文件   android.mk文件

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE := libJNI_ANDROID_TEST

LOCAL_SRC_FILES := libJNI_ANDROID_TEST.so

include $(PREBUILT_SHARED_LIBRARY)

#LOCAL_ALLOW_UNDEFINED_SYMBOLS := true

include $(CLEAR_VARS)

LOCAL_MODULE := JNI_ANDROID_AUDIOS

LOCAL_SRC_FILES := NativePlayers.cpp

LOCAL_LDLIBS += -L$(SYSROOT)/usr/lib -llog

LOCAL_SHARED_LIBRARIES := libJNI_ANDROID_TEST \

include $(BUILD_SHARED_LIBRARY)

7.调用完毕

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值