当前位置: 移动技术网 > IT编程>移动开发>Android > android 源码中添加一个最简单的自启动的本地服务

android 源码中添加一个最简单的自启动的本地服务

2018年09月19日  | 移动技术网IT编程  | 我要评论

西藏地图,南康二手房网,我们结婚了20110101

native service 创建过程学习笔记

a. 在vendor/ /common/目录下创建文件夹native_service
b. 在此文件目录下创建.cpp 文件,并编写程序代码:

#include 
#include 
#include 
#define log_ndebug 0
#define log_tag "hello_world"
#include 
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

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网