http://blog.youkuaiyun.com/luoshengyang/article/details/6571210
1 源代码
derek@u10:~/ics/ics-4.0.4/external/hello$ ls
Android.mk hello.c
hello.c
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#define DEVICE_NAME "/dev/hello"
int main(int argc, char** argv)
{
int fd = -1;
int val = 0;
fd = open(DEVICE_NAME, O_RDWR);
if(fd == -1) {
printf("Failed to open device %s.\n", DEVICE_NAME);
return -1;
}
printf("Read original value:\n");
read(fd, &val, sizeof(val));
printf("%d.\n\n", val);
val = 5;
printf("Write value %d to %s.\n\n", val, DEVICE_NAME);
write(fd, &val, sizeof(val));
printf("Read the value again:\n");
read(fd, &val, sizeof(val));
printf("%d.\n\n", val);
close(fd);
return 0;
}
Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE := hello
LOCAL_SRC_FILES := $(call all-subdir-c-files)
include $(BUILD_EXECUTABLE)
2 编译
derek@u10:~/ics/ics-4.0.4/$ . ./build/envsetup.sh
derek@u10:~/ics/ics-4.0.4/$ mmm ./external/hello
derek@u10:~/ics/ics-4.0.4/$ make snod
3 运行虚拟机,测试bin文件
derek@u10:~/ics/ics-4.0.4$ adb shell
#
# cd /bin
cd: can't cd to /bin
# hello
Read original value:
5.
Write value 5 to /dev/hello.
Read the value again:
5.
1369

被折叠的 条评论
为什么被折叠?



