80,351
社区成员
发帖
与我相关
我的任务
分享
/********************test.h
#ifndef _TEST_H_
#define _TEST_H_
#include <stdio.h>
#include <stdlib.h>
#ifdef __cplusplus
extern "C" {
#endif
extern int test_a();
#ifdef __cplusplus
}
#endif
#endif
/*****************test.c
#include "test.h"
int test_a()
{
int a = 9;
return a;
}
以上用交叉编译器了一个libtest.so
交错编译器
arm-none-linux-gnueabi-gcc test.c -shared -o libtest.so
jni目录下:
android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := native-plasma这是NDK自带例子
LOCAL_SRC_FILES := plasma.c 我在里面代码加了int aa = test_a();
LOCAL_LDLIBS += -lm
LOCAL_LDLIBS +=-llog
LOCAL_LDLIBS +=-landroid
LOCAL_LDLIBS += $(LOCAL_PATH)/inllib/libtest.so //这是加载libtest.so 的路径
LOCAL_STATIC_LIBRARIES := android_native_app_glue
include $(BUILD_SHARED_LIBRARY)
$(call import-module,android/native_app_glue)
然后用NDK命令$NDK/ndk-build一个native-plasma.so 能编译成功
编译器编译项目 在android仿真器 运行该程序 出错 提示 sorry! The application native-plasma (process com.gcx.plasma) has stopped unexpectedly.please try again
我看到log.so opengles.so进入adb shell 在lib目录下能看到 是不是我的test.so 没在这里面所以运行不成功呢
这lib是只读的 加不了
NDK是r5的 SDK也是最新