80 likes | 349 Views
AT91SAM JNI demo project introduction. JNI Demo Project - Overview. Goal Environment Setup Install JDK 6 Install Android SDK Install Eclipse Install ADT for Eclipse Install Android NDK C Native code in JNI demo project are already built as a shared library. You can run the demo directly.
E N D
JNI Demo Project - Overview • Goal • Environment Setup • Install JDK 6 • Install Android SDK • Install Eclipse • Install ADT for Eclipse • Install Android NDK • C Native code in JNI demo project are already built as a shared library. You can run the demo directly. • Reference to http://developer.android.com/sdk/installing.html C functions Android UI button LED JNI
JNI Demo Project - C native code • Provide functions to control LED • Open LED device file, then write 1/0 to the file • Works like following command line: • echo 1 > /sys/class/leds/d2/brightness • echo 0 > /sys/class/leds/d2/brightness • JNI prefix • Composed by: • Java • Name space • package com.example.jnidemo; • Class Name • publicclass JNIDemo extends Activity implements • Function name • For example: • Java_com_example_jnidemo_JNIDemo_turnOnLed • Java_com_example_jnidemo_JNIDemo_turnOffLed • Build as a shared library for JAVA to call • Android.mk • include $(BUILD_SHARED_LIBRARY) • Needs Android NDK to build • ndk-build
Create UI buttons Call JNI interface when clicked publicnativeint turnOnLed(); publicnativeint turnOffLed(); Load native library when class is loaded static { System.loadLibrary("led_control"); } JNI Demo Project - Java code
Use adb tool to create USB connection http://www.at91.com/android4sam/bin/view/Android4SAM/UsingAdb Connect USB cable to EK board (need install USB device driver) Setup environment variable (ANDROID_SDK_HOME) by running command line or add in Environment Variables like the picture Run adb android.bat update adb Modify .android\adb_usb.ini adb start-server Before running JNI demo chmod 666 /sys/class/leds/d2/brightness Change the permission for java application can read/write Deploy in the board adb install *.apk Or using Eclipse IDE Android SDK, Eclipse and ADT installed Import this project to work space Run -> Run As -> Android Application JNI Demo Project - Deploy
JNI Demo Project - Running • Running JNI demo • Click “Turn On/Off LED” to turn on/off LED ‘D2’. • Debug information will be printed in serial port when logcat is running • Debugging in board • logcat & D2
More information about AT91SAM OS Ecosystem AT91SAM Linux Ecosystem http://www.linux4sam.org AT91SAM Android Ecosystem http://www.at91.com/android4sam AT91SAM WinCE Ecosystem http://www.at91.com/windows4sam AT91SAM community forum http://www.at91.com