Android jni build 多个shared library

1、本文以D:\ndk\samples\two-libs 为例,下载ndk解压以后就可以看到这个demo的源文件

2、添加文件

third.h

#ifndef THIRD_H
#define THIRD_H
int third(int x,int y);
#endif /*third_h*/


third.c

#include  "third.h"
int third(int x,int y){
return x*y;
}

3、修改Android.mk文件



LOCAL_PATH:= $(call my-dir)


# first lib, which will be built statically
#
include $(CLEAR_VARS)


LOCAL_MODULE    := libtwolib-first
LOCAL_SRC_FILES := first.c


include $(BUILD_STATIC_LIBRARY)


include $(CLEAR_VARS)
LOCAL_MODULE :=lib-third
LOCAL_SRC_FILES :=third.c
include $(BUILD_STATIC_LIBRARY)


# second lib, which will depend on and include the first one
#
include $(CLEAR_VARS)


LOCAL_MODULE    := libtwolib-second
LOCAL_SRC_FILES := second.c


LOCAL_STATIC_LIBRARIES := libtwolib-first lib-third


include $(BUILD_SHARED_LIBRARY)


3、然后在jni目录,执行ndk-build(需要把ndk目录添加到环境变量path里面)

4、java文件添加 public native int mult(int x,int y);

我们就添加了乘法的功能

值得注意的是:LOCAL_STATIC_LIBRARIES如果有多个是以空格为分隔的,并不是逗号

你可能感兴趣的:(Android)