文档库 最新最全的文档下载
当前位置:文档库 › NDK动态库的调用(一)

NDK动态库的调用(一)

NDK动态库的调用(一)

NDK动态库的调用(一)

NDK so mk;

so2so

so

A.

eoe.Java :Java

test01.c so libtest.so libtest.so libtutorial.so.tutorial01.c tutorial02.c tutorial02.h libtutorial.so

B. mk java

java C/C++

1.packageeoe.example.test;

2.

3.importandroid.R.integer;

4.importandroid.app.Activity;

5.importandroid.widget.TextView;

6.importandroid.os.Bundle;

7.

8.publicclasstest01extendsActivity{

9.

10./**Calledwhentheactivityisfirstcreated.*/

11.@Override

12.publicvoidonCreate(BundlesavedInstanceState){

13.

14.super.onCreate(savedInstanceState);

15.TextViewtv=newTextView(this);

16.inta=getinformation();

17.Stringlls=a+"";

https://www.wendangku.net/doc/c514329014.html,.setText(lls);

19.setContentView(tv);

20.}

21.

22.publicnativeintgetinformation();

23.

24.static{

25.System.loadLibrary("test");

26.}

27.}

28.Android.mkLOCAL_PATH:=$(callmy-dir)

29.#

30.include$(CLEAR_VARS)

31.#

32.LOCAL_MODULE:=tutorial

33.#

34.LOCAL_SRC_FILES:=tutorial01.ctutorial02.c

35.#

36.include$(BUILD_SHARED_LIBRARY)

37.#libtutorial.so

38.include$(CLEAR_VARS)

39.#

40.LOCAL_MODULE:=test

41.#

42.LOCAL_SRC_FILES:=test01.c

43.#

44.LOCAL_LDLIBS:=-ldl-llog

45.#libtest.so libdl.so:liblog.so system/lib

46.include$(BUILD_SHARED_LIBRARY)

47.#

48.test01.c

49.#include

50.#include

51.#include

52.#include

53.#include

54.#defineLOG_TAG"libgl2jni"

55.#defineLOGI(...)__android_log_print(ANDROID_LOG_INFO,LOG_TAG,__VA_ARGS__)

56.#defineLOGE(...)__android_log_print(ANDROID_LOG_ERROR,LOG_TAG,__VA_ARGS__)

57.

58.//externintgetinformation();

59.jintJava_com_example_test_test01_getinformation(JNIEnv*env,jobjectthiz){

60.//getinformation();??

thr.sofilewillloadtothesdcardwiththefolderdata/data/com.example.test/lib/

61.void*filehandle=dlopen("/data/data/com.example.test/lib/libtutorial.so",RTLD_LAZY);

62.intll=-1;

63.if(filehandle){

64.LOGI("opensosuccess!");

65.int(*getinformation)();

66.getinformation=dlsym(filehandle,"getinformation");

67.if(getinformation){

68.LOGI("callfunctiongetinformationOK!");

69.ll=getinformation();

70.}else{

71.ll=-3;

72.LOGE("callfunctiongetinformation!ERROR!");

73.}

74.LOGI("returnvalue=%d",ll);

75.dlclose(filehandle);

76.filehandle=0;

77.}else{

78.ll=-2;

79.LOGE("opensoERROR!");

80.}

81.returnll;

82.}

相关文档