android环境编译动态库

super_monkey/test$ ls
Android.mk test_me.c test_me.h

test_me.h

复制代码
#ifndef TEST_ME_H
#define TEST_ME_H

#ifdef __cplusplus
extern "C" {
#endif

void test();

#ifdef __cplusplus
}
#endif

#endif
复制代码

test_me.c

复制代码
#include <stdio.h>
#include "test_me.h"

void test()
{
    printf("---------1111111111111---------\n");

}
复制代码

Android.mk

复制代码
LOCAL_PATH:= $(call my-dir)

include $(CLEAR_VARS)

LOCAL_SRC_FILES = \
    test_me.c

LOCAL_MODULE := libTestme
include $(BUILD_SHARED_LIBRARY)
复制代码

编译动态库

$make  libTestme

super_monkey/hello$ ls
Android.mk hello.c

复制代码
#include <stdio.h>
#include "test_me.h"

int main(void){
    printf("Hello World!\n");
    test();
    return 0;
}
复制代码

Android.mk

复制代码
LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)


LOCAL_C_INCLUDES += \
    $(LOCAL_PATH)/../test

LOCAL_MODULE    := hello
LOCAL_SRC_FILES := hello.c

LOCAL_SHARED_LIBRARIES := libTestme

include $(BUILD_EXECUTABLE)
复制代码

自动编译动态库,并编译可执行文件。

make hello

 

adb push libTestme.so /system/lib64/

adb push hello /data

kirin980:/data # ./hello
Hello World!
---------1111111111111---------

posted @ 2018-03-03 17:09  牧 天  阅读(627)  评论(0)    收藏  举报