美文网首页
Android MK导入第三方静态库.a编译成执行文件,或者SO

Android MK导入第三方静态库.a编译成执行文件,或者SO

作者: Lazy1 | 来源:发表于2022-08-24 18:07 被阅读0次
  • 目录结构
image.png
  • 生成.a静态库

static.h

int add( int x, int y);

static.cpp

#include "include/static.h"
int add( int x, int y)
{
     return x + y;
}

  • Android mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE    := static_add
LOCAL_SRC_FILES := static.cpp
include $(BUILD_STATIC_LIBRARY)

  • 使用静调库
image.png

share.h

# include "static.h"
int test_add( int x, int y);

静态库的头文件 ,static.h

share.cpp


# include "include/share.h"
# include "include/static.h"
# include "log/log.h"

int test_add( int x, int y)
{
     // 调用static里面的方法
     return add(x, y);
}



int main() {
      test_add(5,6);
 ALOGE("test_addtest_addtest_addtest_addtest_addtest_add");
    return 0;

}

static_add.a 编译好的静态库

  • Android mk

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE    := static_add
LOCAL_SRC_FILES := libstatic_add.a
include $(PREBUILT_STATIC_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE    := share_add
LOCAL_STATIC_LIBRARIES := static_add
LOCAL_SHARED_LIBRARIES := liblog
LOCAL_SRC_FILES := share.cpp
include $(BUILD_EXECUTABLE)

最后编译,会在system/bin 下生成一个可执行的二进制文件share_add,拷贝到手机即可执行测试

相关文章

网友评论

      本文标题:Android MK导入第三方静态库.a编译成执行文件,或者SO

      本文链接:https://www.haomeiwen.com/subject/oheogrtx.html