For compiling the module, it's important that you use the same kernel source that is installed in your device. Otherwise, you cannot install the module.
a. Go to the code that contains an example of kernel module for Android (for instance, [your_code]/module/intercept);
b. Update the makefile to point to your kernel source code;
c. You need to set some env variables, including the cross-compiler. In this case, you can use the ones provided by the Android source, in the folder prebuilts:
@desktop:$ export CROSS_COMPILE=[android_sdk]
@desktop:$ export ARCH=arm
@desktop:$ export PATH=$PATH:
(a kernel module file will be generated ([your_module].ko) and this is the one that we need to install in our rooted device)
d. Copy the .ko file to the device using the following command:
@desktop:$ adb push [your_module].ko /data/local/tmp
e. Install the kernel module using the following commands:
@desktop:$ adb shell
@android:$ cd /data/local/tmp
@android:$ insmod [your_module].ko
f. You might get some errors, such as "function not implemented". To check more details about what's wrong, you can check the log file by typing the following command.