模板: system/extras/su/Android.mk
创建一个main.c文件,在里面打印一些日志
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <pthread.h>
void *my_test_thread (void *args)
{
printf("my_test_thread running...\n");
return NULL;
}
int main(void)
{
int fd = -1;
pthread_t tid;
printf("hello world!\n");
fd = open("/dev/input/event0", O_RDWR);
if(fd < 0)
{
printf("open error: %s", strerror(errno));
exit(1);
}
printf("fd = %d\n", fd);
pthread_create(&tid, NULL, my_test_thread, NULL);
pthread_join(tid, NULL);
return 0;
}
创建一个Android.mk文件
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_CFLAGS += \
-Wno-error \
-Wno-unused-parameter
LOCAL_SRC_FILES := main.c
LOCAL_MODULE := hello_test
include $(BUILD_EXECUTABLE)
编译结果
先初始化安卓环境变量,然后进入到该目录下面执行该命令:mm
生成的目标文件有如下:
中间文件: out\target\product\sl8541e_cus_go\obj\EXECUTABLES\hello_test_intermediates
目标文件:out/target/product/sl8541e_cus_go/system/bin/hello_test
编译生成的文件
如何验证以及运行该程序
adb push system\bin\hello_test /system/bin/
进入到system/bin目录下面执行 ./hello_test
日志打印
sl8541e_cus_go:/system/bin # ./hello_test
hello world!
fd = 3
my_test_thread running...
sl8541e_cus_go:/system/bin #