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---------