Native Service 创建过程学习笔记
a. 在vendor/ /common/目录下创建文件夹Native_service
b. 在此文件目录下创建.cpp 文件,并编写程序代码:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define LOG_NDEBUG 0
#define LOG_TAG "hello_world"
#include <utils/Log.h>
int main (int argc ,int *argv )
{
ALOGD("hello world");
return 0;
}
c. 在此目录下创建.mk文件,编写Android makefile 程序代码:
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := optional
LOCAL_SRC_FILES := HelloWorld.cpp
LOCAL_STATIC_LIBRARIES := libcutils liblog
LOCAL_MODULE := helloworld
include $(BUILD_EXECUTABLE)
d . 在源码中编译所写服务:
cd Android_1008M/
source build/envsetup.sh
lunch
mmm /vendor/ /common/native_services
e. 编译成功后, 将服务打包到项目中,打开products.mk文件
找到如下代码位置:
###############################################################
################### TARGET FOR COMMON #####################
###############################################################
PRODUCT_PACKAGES += \
AMapNetworkLocation \
irremote \
sougou_input \
zigbeeSerianlportTest \
Market \
SixLoWPanUpgrade \
SmartHome \
BugReport \
UCBrowser \
helloworld //在其后面添加自己写的服务helloworld (小写)。
f. 增加.rc文件:在init.target.rc文件中添加service:
# hello world
service helloworld /system/bin/helloworld
class late_start
user system
grop system
g. 重新编译整个源码文件,将所写服务加到源码中,并将所得的系统烧到手机中:
source bulid/envsetup.sh
lunch
make –j32
h . 查看自己所写的服务 :
打开cmd,输入命令 adb logcat –s hello_world