After several days, I finally spent some time writing my blog. I will go on to the previous article to introduce how to compile the JNI method corresponding to the Hal layer (Hardware Abstraction Layer.
All mentioned here are compiled in the ICS source code.
1. Define the JNI layer interface
Go to the android-4.0.4_r1.2/hardware/libhardware/include/hardware directory and create the TTT. h file with the following content:
# Ifndefandroid_ttt_interface_h # defineandroid_ttt_interface_h # include <Hardware/hardware. h >__ begin_decls // define module ID # struct "TTT" // hardware module struct ttt_module_t {struct hw_module_t common ;}; // hardware interface structstruct ttt_device_t {struct hw_device_t common; int FD; int (* set_val) (struct ttt_device_t * Dev, int Val); int (* get_val) (struct ttt_device_t * Dev, int * val); };__ end_decls # endif
2. Implement JNI layer interface functions
Go to the android-4.0.4_r1.2/frameworks/base/services/JNI directory and create the com_android_server_tttservice.cpp file with the following content:
#define LOG_TAG "TTTService"#include "jni.h"#include "JNIHelp.h"#include "android_runtime/AndroidRuntime.h"#include <utils/misc.h>#include <utils/Log.h>#include
3. Add JNI initialization call
Modify the onload. cpp file under the android-4.0.4_r1.2/frameworks/base/services/JNI directory and add the following sentence before return in the jni_onload function:
register_android_server_TTTService(env);
At the same time, add the following statement to the namespace in the file:
int register_android_server_TTTService(JNIEnv* env);
In this way, during system initialization, The register_android_server_tttservice method will be called to load the JNI method.
4. Add the JNI compilation Configuration
Modify the Android. mk file under the android-4.0.4_r1.2/frameworks/base/services/JNI directory and add the following line to the local_src_files variable:
com_android_server_TTTService.cpp \
Here is the compilation configuration.
5. Start Compilation
root@brantyou-ubuntu:~/workspace/android-4.0.4_r1.2# . build/envsetup.sh including device/moto/stingray/vendorsetup.shincluding device/moto/wingray/vendorsetup.shincluding device/samsung/crespo4g/vendorsetup.shincluding device/samsung/crespo/vendorsetup.shincluding device/samsung/maguro/vendorsetup.shincluding device/samsung/smdkc110/vendorsetup.shincluding device/samsung/smdkv210/vendorsetup.shincluding device/samsung/torospr/vendorsetup.shincluding device/samsung/toro/vendorsetup.shincluding device/samsung/tuna/vendorsetup.shincluding device/ti/panda/vendorsetup.shincluding sdk/bash_completion/adb.bashroot@brantyou-ubuntu:~/workspace/android-4.0.4_r1.2#
Root @ brantyou-Ubuntu :~ /Workspace/android-4.0.4_r1.2 # Mmm frameworks/base/services/JNI ========================== ======================== relplatform_version = 4.0.4target _ Product = fulltarget_build_variant = engtarget_build_type = role = target_arch = Signature = armv7-aHOST_ARCH = x86host_ OS = linuxhost_build_type = releasebuild_id = imm76i ==================================== ======== make: enter Directory '/home/brantyou/workspace/android-4.0.4_r1.2' target thumb C ++: libandroid_servers <= frameworks/base/services/JNI/com_android_server_helloservice.cpptarget thumb C ++: libandroid_servers <= frameworks/base/services/JNI/com_android_server_tttservice.cpptarget thumb C ++: libandroid_servers <= frameworks/base/services/JNI/onload. cppmake: *** you can create "Out/target/product/generic/obj/shared_libraries/L Ibandroid_servers_intermediates/linked/libandroid_servers.so "indicates the target" out/target/product/generic/obj/lib/libsystem_server.so ". Stop. Make: Leave the directory "/home/brantyou/workspace/android-4.0.4_r1.2" root @ brantyou-Ubuntu :~ /Workspace/android-4.0.4_r1.2 #
Low Oil ~~~ An error occurred, prompting that the libsystem_server.so file could not be found.
Run the following command to generate the libsystem_server.so file:
root@brantyou-ubuntu:~/workspace/android-4.0.4_r1.2# make libsystem_server
Prompt after generation:
Install: out/target/product/generic/system/lib/libvorbisidec.soInstall: out/target/product/generic/system/lib/libstagefright_yuv.soInstall: out/target/product/generic/system/lib/libdrmframework.soInstall: out/target/product/generic/system/lib/libchromium_net.soInstall: out/target/product/generic/system/lib/libstagefright_amrnb_common.soInstall: out/target/product/generic/system/lib/libstagefright_enc_common.soInstall: out/target/product/generic/system/lib/libstagefright_avc_common.soInstall: out/target/product/generic/system/lib/libstagefright.soInstall: out/target/product/generic/system/lib/libstagefright_omx.soInstall: out/target/product/generic/system/lib/libmediaplayerservice.soInstall: out/target/product/generic/system/lib/libinput.soInstall: out/target/product/generic/system/lib/libsystem_server.soroot@brantyou-ubuntu:~/workspace/android-4.0.4_r1.2#
Okay, this problem is solved. We will continue to compile this JNI.
Root @ brantyou-Ubuntu :~ /Workspace/android-4.0.4_r1.2 # Mmm frameworks/base/services/JNI ========================== ======================== relplatform_version = 4.0.4target _ Product = fulltarget_build_variant = engtarget_build_type = role = target_arch = Signature = armv7-aHOST_ARCH = x86host_ OS = linuxhost_build_type = releasebuild_id = imm76i ==================================== ======== make: enter Directory '/home/brantyou/workspace/android-4.0.4_r1.2' target sharedlib: libandroid_servers (Out/target/product/generic/obj/shared_libraries/libandroid_servers_intermediates/linked/libandroid_servers.so) Target symbolic: libandroid_servers (Out/target/product/generic/symbols/system/lib/libandroid_servers.so) Target Strip: libandroid_servers (Out/target/product/generic/obj/lib/libandroid_servers.so) install: Out/target/product/generic/system/lib/libandroid_servers.somake: Leave the directory "/home/brantyou/workspace/android-4.0.4_r1.2" root @ brantyou-Ubuntu :~ /Workspace/android-4.0.4_r1.2 #
Good. This time the compilation has been completed successfully.
Next we need to re-package the system. IMG, And the JNI method we have written is included:
root@brantyou-ubuntu:~/workspace/android-4.0.4_r1.2# make snod============================================PLATFORM_VERSION_CODENAME=RELPLATFORM_VERSION=4.0.4TARGET_PRODUCT=fullTARGET_BUILD_VARIANT=engTARGET_BUILD_TYPE=releaseTARGET_BUILD_APPS=TARGET_ARCH=armTARGET_ARCH_VARIANT=armv7-aHOST_ARCH=x86HOST_OS=linuxHOST_BUILD_TYPE=releaseBUILD_ID=IMM76I============================================make snod: ignoring dependenciesTarget system fs image: out/target/product/generic/system.imgout/target/product/generic/system.img total size is 44107008root@brantyou-ubuntu:~/workspace/android-4.0.4_r1.2#
In this way, the JNI we wrote is successfully packaged into system. IMG.
This chapter ends. The next chapter describes how to write the corresponding service based on the JNI interface and write the corresponding Android program to access the service.