Android.mk 预编译可执行程序

模板: 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 #
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值