Yes, you can create kernel modules with NDK. Note that this works best with the Linux system (I am told that Linux x86_64 is a supported environment), because it is more difficult to cross-compile the kernel code on case-sensitive file systems (for example, those that appear by default on Windows and Mac systems ) and because the creation of kernel modules requires the creation of binary ELF files (modpost), which require that ELF headers are usually present only on Linux. Nonetheless...
First you need to get the source code for the same kernel on your device and make sure that the configuration matches your device. (otherwise it is likely that you will confuse the build system)
Secondly, you need to determine where the cross-compiler is used in your Android NDK. Here is how I found mine:
$ cd $NDK_HOME $ find . | grep '\-gcc$' ./toolchains/arm-eabi-4.4.0/prebuilt/linux-x86/bin/arm-eabi-gcc ./toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/bin/arm-linux-androideabi-gcc
(note $NDK_HOME is where I installed Android NDK)
Third, you need to add the $NDK_HOME/toolchains/arm-eabi-4.4.0/prebuilt/linux-x86/bin (or wherever it is located on your system) to your PATH environment variable.
Then you need to export two environment variables:
export ARCH=arm export CROSS_COMPILE=arm-eabi-
(note that the prefix arm-eabi- matches what we saw in the find . When the kernel is built, commands such as gcc and ld will have a prefix with this. you built the x86 platform, I expect that you will have to adjust it. I only have built-in modules for ARM.)
Then you must compile the kernel. (To do this, I pulled /proc/config.gz from my Android device, ran zcat config.gz > .config in the kernel source directory, and then ran make menuconfig && make .) Sound gurus can know some shortcuts here, but I couldn’t set correctly create the source directory of the kernel to create the module without the actual assembly. (If the kernel in the assembly tree matches your device, you do not need to actually update the kernel, you can simply insert the modules.)
Finally, I used the usual process to build kernel modules from the source. Typically, kernel modules will have a parameterized assembly, which will somehow be read in the directory of the kernel source tree, and then invoke the assembly. At this point, while the kernel source tree is configured correctly and ARCH and CROSS_COMPILE configured, your module should build!
Good luck with that. I am sure there is some difference between the devices.