2020-11-02 Android 编译成静态编译库a以及调用实例

             Android 编译成静态编译库a以及调用实例

 

一、编译静态库。

    1、Amdroid.mk

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE:=libtest_static
LOCAL_SRC_FILES := helloworld.c
LOCAL_LDLIBS := -llog
LOCAL_CFLAGS += -DRIL_SHLIB
include $(BUILD_STATIC_LIBRARY)

   2、helloworld.c

#include <stdio.h>
#include <string.h>
#include <utils/Log.h>

#include "helloworld.h"


int android_function(int a,int b) 
{
	int ret=0;
    ret=a+b;
    ALOGD("android_function a+b=%d  ret=%d \n",ret,ret);
    return ret;
}

3、helloworld.h

#include <stdio.h>
#include <string.h>
#include <utils/Log.h>
int android_function(int a,int b);

4、编译mmm hardware/rockchip/static_library/,生成out/target/product...rm/STATIC_LIBRARIES/libtest_static_intermediates/libtest_static.a文件。

 

二、调用静态库

       1、Android.mk

include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE:=call_static
LOCAL_SHARED_LIBRARIES:=liblog libc libcutils
LOCAL_STATIC_LIBRARIES:=libtest_static
LOCAL_LDFLAGS := $(LOCAL_PATH)/libtest_static.a
LOCAL_SRC_FILES :=call_static.c
LOCAL_LDLIBS := -llog
include $(BUILD_EXECUTABLE)

  2、call_static.c

#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <termios.h>
#include <errno.h>
#include <utils/Log.h>
#include <stdbool.h>
#include <stdlib.h>
#include <cutils/properties.h>
#include "helloworld.h"

#define LOG_TAG "CALL STATIC"


int main()
{
    
	ALOGD("*************begin*************");//
    android_function(8,9);
	ALOGD("*************end*************");
	
    return 0;
}

3、把libtest_static.a 文件copy过来到根目录。

 

4、编译mmm hardware/rockchip/call_static/

 

三、adb push call_static  /system/bin/ 执行验证

 

四,所用到的文件,下载路径https://download.csdn.net/download/qq_37858386/13082934

 

五、LOCAL_SHARED_LIBRARIES和LOCAL_STATIC_LIBRARIES是引入系统的,LOCAL_LDFLAGS是引用第三方的。参考https://blog.csdn.net/qq840727854/article/details/54782700?utm_medium=distribute.pc_relevant_t0.none-task-blog-BlogCommendFromMachineLearnPai2-1.channel_param&depth_1-utm_source=distribute.pc_relevant_t0.none-task-blog-BlogCommendFromMachineLearnPai2-1.channel_param

 

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值