Using source code to compile the Java class Library of Android system
1. Writing Java projects and android.mk files
├──android.mk
└──src
└──com
└──lhw
└──framework
└──led
Led.java file
Package com.lhw.framework.led;
/**
* LED Operation Library
* @author Micky Liu
/public class LEDs {public
Boolean turnon () {return
tru e;
}
public Boolean turnoff () {return
true;
}
ANDROID.MK file
Local_path: = $ (call My-dir)
local_src_files : = $ (call All-java-files-under, SRC)
local_module : = framework_led
local_module_tags : = framework_led
local_java_libraries : =
local_static _java_libraries: =
include $ (build_java_library)
2, compile
Mmm/home/administrator/workspace/android_test/framework_led
Compilation results:
Install:out/target/product/generic/system/framework/framework_led.jar
using source code to compile the Android system JNI Dynamic Library
1, code and ANDROID.MK writing
├──jni
│ ├──android.mk
│ └──led.c
Led.c
#include <jni.h>
#include <stdio.h>
jboolean java_com_lhw_led_led_turnon (jnienv *env, Jclass Thiz)
{return
jni_true;
}
Jboolean Java_com_lhw_led_led_trunoff (jnienv *env, Jclass thiz)
{return
jni_true;
}
Note: The method name rule is: Java_ Package Name _ Class Name _ Method name, you can use the Javah command to generate the required. h header file According to the Java file. Of course, a better approach is to implement dynamic registration through Jni_onload and androidruntime::registernativemethods, so that you don't have to ignore the method name rules. Here is just a simple example, followed by an example to implement dynamic registration.
Android.mk
Local_path: = $ (call My-dir)
local_src_files: = led.c
local_module : = Led_jni local_module_tags : = Led_jni
local_prelink_module : = False
local_shared_libraries: = libc
include $ (build_shared_ LIBRARY)
2, compile
Mmm/home/administrator/workspace/android_test/jni
Compilation results:
Install:out/target/product/generic/system/lib/led_jni.so