[FE training-materials-updates] Split the JNI lab in half

Maxime Ripard maxime.ripard at free-electrons.com
Tue Jun 3 12:10:11 CEST 2014


Repository : git://git.free-electrons.com/training-materials.git

On branch  : master
Link       : http://git.free-electrons.com/training-materials/commit/?id=5b7bd5c1af035ae42f63eb5ec8fc00d3b9c3cb48

>---------------------------------------------------------------

commit 5b7bd5c1af035ae42f63eb5ec8fc00d3b9c3cb48
Author: Maxime Ripard <maxime.ripard at free-electrons.com>
Date:   Tue Jun 3 12:09:25 2014 +0200

    Split the JNI lab in half
    
    Signed-off-by: Maxime Ripard <maxime.ripard at free-electrons.com>


>---------------------------------------------------------------

5b7bd5c1af035ae42f63eb5ec8fc00d3b9c3cb48
 Makefile                                           |    4 +-
 labs/android-framework/android-framework.tex       |   40 +++++++++++++++++++
 labs/android-jni-library/android-jni-library.tex   |   41 +++++++++-----------
 .../android-framework-lab.tex                      |    4 +-
 .../android-native-layer-lab-jni.tex}              |    4 +-
 5 files changed, 64 insertions(+), 29 deletions(-)

diff --git a/Makefile b/Makefile
index c6f1884..c6eb915 100644
--- a/Makefile
+++ b/Makefile
@@ -194,6 +194,7 @@ ANDROID_SLIDES = \
 		android-native-layer-dalvik \
 		android-native-layer-hal \
 		android-native-layer-jni \
+		android-native-layer-lab-jni \
 		android-framework-title \
 		android-framework-native-services \
 		android-framework-ipc \
@@ -280,9 +281,10 @@ ANDROID_LABS  = setup \
 		android-new-board \
 		android-adb \
 		android-native-library \
-		android-system-customization \
 		android-native-app \
+		android-system-customization \
 		android-jni-library \
+		android-framework \
 		android-application \
 
 BOOTTIME_LABS = boottime-install \
diff --git a/labs/android-framework/android-framework.tex b/labs/android-framework/android-framework.tex
new file mode 100644
index 0000000..42542f9
--- /dev/null
+++ b/labs/android-framework/android-framework.tex
@@ -0,0 +1,40 @@
+\subchapter{Develop a Framework Component}{Learn to integrate it in
+  Android a Framework component}
+
+After this lab, you will be able to
+\begin{itemize}
+  \item Modify the Android framework
+  \item Use JNI bindings
+\end{itemize}
+
+\section{Write and integrate the component in the build system}
+
+Aside from the \code{jni} folder, you'll find in the \code{frameworks}
+folder a \code{java} folder that contains a Java Interface,
+\code{MissileBackendImpl}. In the same folder, write the
+\code{USBBackend} class implementing this interface that uses your
+bindings. You have an example of such a class in the
+\code{DummyBackend.java} file.
+
+Now you can integrate it into the build system, so that it generates a .jar
+library that is in our product, with the proper dependencies expressed.
+
+You can find documentation about how to integrate device-specific parts of the
+framework in the \code{device/sample/frameworks} folder.
+
+\section{Testing the bindings}
+
+We should now have a system with the files
+\code{/system/framework/com.fe.android.backend.jar}, containing the Java
+classes, \code{/system/lib/liblauncher_jni.so}, containing the JNI bindings and
+\code{/system/lib/libusb.so}.
+
+Test what you did using the Main class present in the Java source code
+by directly invoking Dalvik through the \code{app_process}
+command. You will have to provide both the classpath and the class
+name to make it work and should look like
+\code{CLASSPATH=path/to/java.jar app_process /system/bin com.fe.android.Main}
+
+Once you have a solution that works, you can ask your instructor to 
+give you a URL where Free Electrons' solution is available, and compare
+it with what you implemented.
diff --git a/labs/android-jni-library/android-jni-library.tex b/labs/android-jni-library/android-jni-library.tex
index 5399074..70dedf6 100644
--- a/labs/android-jni-library/android-jni-library.tex
+++ b/labs/android-jni-library/android-jni-library.tex
@@ -5,8 +5,6 @@ After this lab, you will be able to
 \begin{itemize}
   \item Develop bindings from Java to C
   \item Integrate these bindings into the build system
-  \item Modify the Android framework
-  \item Use JNI bindings
 \end{itemize}
 
 \section{Write the bindings}
@@ -21,40 +19,39 @@ You will mostly have to modify function prototypes from your previous
 application to make it work with JNI.
 
 As a reminder, JNI requires the function prototype to be like:
-\code{JNIEXPORT <jni type> JNICALL Java_<package_class>_<function_name>(JNIEnv *env, jobject this)}.
+\code{JNIEXPORT <jni type> JNICALL Java_<package>_<class>_<function_name>(JNIEnv *env, jobject this)}.
 Beware that the function name can't have any underscore in its name
 for JNI to function properly.
 
-Aside from the \code{jni} folder, there is also a \code{java} folder that
-contains a Java Interface, \code{MissileBackendImpl}. In the same folder,
-write the \code{USBBackend} class implementing this interface that uses your
-bindings. You have an example of such a class in the \code{DummyBackend.java}
-file.
+The package we are going to use is \code{com.fe.android.backend}, and
+the class name is \code{USBBackend}. We are going to need the
+functions \code{fire}, \code{stop}, \code{initUSB}, \code{freeUSB},
+\code{moveDown}, \code{moveUp}, \code{moveLeft} and \code{moveRight}.
+
+Aside from the \code{jni} folder, there is also a \code{java} folder
+that contains a Java Interface, \code{MissileBackendImpl}. In the same
+folder, write the \code{USBBackend} class implementing this interface
+that uses your bindings. You have an example of such a class in the
+\code{DummyBackend.java} file.
 
 \section{Integrate it in the build system}
 
-Now you can integrate it into the build system, so that it generates a .jar
-library that is in our product, with the proper dependencies expressed.
+Now you can integrate it into the build system, by writing an
+\code{Android.mk} as usual.
 
-You can find documentation about how to integrate device-specific parts of the
-framework in the \code{device/sample/frameworks} folder.
+The library should be called \code{liblauncher_jni}.
 
 \section{Testing the bindings}
 
 We should now have a system with the files
-\code{/system/framework/com.fe.android.backend.jar}, containing the Java
-classes, \code{/system/lib/liblauncher_jni.so}, containing the JNI bindings and
+\code{/system/lib/liblauncher_jni.so}, containing the JNI bindings and
 \code{/system/lib/libusb.so}.
 
-Test what you did using the Main class present in the Java source code
-by directly invoking Dalvik through the \code{app_process}
-command. You will have to provide both the classpath and the class
-name to make it work and should look like
-\code{CLASSPATH=path/to/java.jar app_process /system/bin com.fe.android.Main}
+Test what you did so far by using the \code{TestJNI.apk} application
+you'll find in the \code{felabs/android} directory.
 
-Once you have a solution that works, you can ask your instructor to 
-give you a URL where Free Electrons' solution is available, and compare
-it with what you implemented.
+Install it using adb, and make sure that you see a succesful message
+in the logs after running it.
 
 \section{Going further}
 
diff --git a/slides/android-framework-lab/android-framework-lab.tex b/slides/android-framework-lab/android-framework-lab.tex
index 01e114d..e2309fa 100644
--- a/slides/android-framework-lab/android-framework-lab.tex
+++ b/slides/android-framework-lab/android-framework-lab.tex
@@ -1,9 +1,7 @@
 \setuplabframe
-{Develop a JNI Library}
+{Develop a Framework Component}
 {
   \begin{itemize}
-  \item Develop bindings from Java to C
-  \item Integrate these bindings into the build system
   \item Modify the Android framework
   \item Use JNI bindings
   \end{itemize}
diff --git a/slides/android-framework-lab/android-framework-lab.tex b/slides/android-native-layer-lab-jni/android-native-layer-lab-jni.tex
similarity index 63%
copy from slides/android-framework-lab/android-framework-lab.tex
copy to slides/android-native-layer-lab-jni/android-native-layer-lab-jni.tex
index 01e114d..93d172a 100644
--- a/slides/android-framework-lab/android-framework-lab.tex
+++ b/slides/android-native-layer-lab-jni/android-native-layer-lab-jni.tex
@@ -1,10 +1,8 @@
 \setuplabframe
-{Develop a JNI Library}
+{Develop a JNI library}
 {
   \begin{itemize}
   \item Develop bindings from Java to C
   \item Integrate these bindings into the build system
-  \item Modify the Android framework
-  \item Use JNI bindings
   \end{itemize}
 }



More information about the training-materials-updates mailing list