Jni中执行ndk-build,编译第三方静态库(.a)和动态库(.so)的Android.mk文件写法

版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/langxm2006/article/details/54565718

Jni中执行ndk-build,编译第三方静态库(.a)和动态库(.so)的Android.mk文件写法


Android Studio编译JNI接口,当需要调用第三方静态库或者动态库时,正确配置Android.mk文件(jni文件夹中)中是生成自己库的关键,下面是ndk-build执行所需的Android.mk文件文件内容,可做为一个例子,其中Add与Sub做为两个动态库引入,Mul与Div做为两个静态库引入。(注:执行ndk-build之前把Add.so、Sub.so、Mul.a、Div.a拷贝到jni文件夹下


# Copyright (C) 2017 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#


LOCAL_PATH := $(call my-dir)

# load shared library
include $(CLEAR_VARS)
LOCAL_MODULE    := Add
LOCAL_SRC_FILES := libAdd.so
include $(PREBUILT_SHARED_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE    := Sub
LOCAL_SRC_FILES := libSub.so
include $(PREBUILT_SHARED_LIBRARY)

# load static library
include $(CLEAR_VARS)
LOCAL_MODULE    := Mul
LOCAL_SRC_FILES := libMul.a
include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE    := Div
LOCAL_SRC_FILES := libDiv.a
include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)

LOCAL_MODULE    := JniFunction
LOCAL_SRC_FILES := JniFunction.c

LOCAL_SHARED_LIBRARIES := Add Sub
LOCAL_STATIC_LIBRARIES := Mul Div

include $(BUILD_SHARED_LIBRARY)

Android Studio测试Demo Project链接下载demo
展开阅读全文

没有更多推荐了,返回首页