Native Service creation process learning notes
a. Create the folder native service in the vendor / common / directory
b. Create a. cpp file in this file directory, and write the program code:
#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. Create. mk file in this directory, and write Android makefile program code:
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. compile the written service in the source code:
cd Android_1008M/
source build/envsetup.sh
lunch
mmm /vendor/ /common/native_services
e. After the compilation is successful, package the service into the project and open the products.mk file
Locate the following code location:
###############################################################
################### TARGET FOR COMMON #####################
###############################################################
PRODUCT_PACKAGES += \
AMapNetworkLocation \
irremote \
sougou_input \
zigbeeSerianlportTest \
Market \
SixLoWPanUpgrade \
SmartHome \
BugReport \
UCBrowser \
helloworld //Add your own service helloworld (lowercase) after it.
f. Add. RC file: add service in init.target.rc file:
# hello world
service helloworld /system/bin/helloworld
class late_start
user system
grop system
g. Recompile the whole source file, add the written services to the source code, and burn the resulting system into the mobile phone:
source bulid/envsetup.sh
lunch
make –j32
h. view the services you write:
Open cmd, and enter the command adb logcat – s hello? World