Game Development Reference
In-Depth Information
Figure 2-7. logcat output for the project
In the output, notice the following lines:
Trying to load lib /data/data/ch02.project/files/libch02.so ...
Added shared lib /data/data/c69+h02.project/files/libch02.so ...
These are JNI messages that tell us the library loaded successfully and the native methods can now
be invoked within Java. The lines in green represent the callbacks performed by the native library calling
the jni.Natives.OnMessage() method. Success! You have taken the first and most difficult step in
building hybrid games for Android.
What's Next?
In this chapter, you have taken the first steps for building a hybrid game using JNI by learning how to create
the main Java activity and loading a native library within it. Next, you learned about Java native methods using
the native keyword plus the C header file required to implement them. You also learned some useful C tricks,
such as converting Java arrays to C arrays, getting the size of a Java array, and invoking Java methods within C.
You then learned how to troubleshoot common mistakes and test the native library in the emulator.
Things are getting more exciting by the minute.
This and the previous chapter provide the basic foundation if you are planning to port a game that
has significant Linux C code to the Android platform. In the next chapter, you will learn how easy to use
and powerful Android can be if you plan to build a Java-only game.
Search WWH ::




Custom Search