1) game development, the engine layer is implemented in C + +, but sometimes in order to integrate the SDK, call Android native, it is inevitable to think--c++ layer how to call the Java layer?
2) The Android layer calls the C + + library to complete some features that are also common. Development will inevitably think about how to use Java to invoke C + + problems.
The most recent project requirement is that Java calls C + + code to accomplish some of the functionality.
Case 1. How C + + calls the Java layer.
Get a rough look at the Internet.
Jnimethodinfo, Jnihelper C + + class to implement, by importing the relevant header file, introduced into the project.
The invocation requires attention to the delivery of C + + parameters, the method signature, and the receipt of the value returned by Java.
Reference: http://www.himigame.com/android-game/725.html
Skip over ~
Case 2. The Java layer calls C + + code.
Java calls C + + code by calling the. So package (c + + file compiled file) to implement: the build of the so package is supported by the ANDROID-NDK library.
In the Android project you created, you first need to create a JNI folder. NDK compilation requires jni/android.mk files, jni/application.mk files.
The Android.mk file is used to think that the NDK describes what C files need to be compiled, and the Application.mk file is used to describe the ABI that needs to be compiled, that is, the type of CPU.
You can refer to the SAMPLES/HELLO-JNI project under ANDROID/NDK.
Call your own C + + file, first create your own C + + file, and then add it to the Android.mk file,
To the NDK, my custom C + + file will also participate in the program compilation and be used by Java for invocation.
The last picture says:
COCOS2DX game is also done by this way, on the Android phone end of the run.
For example, the Android program starts, enters the static library from an activity, and then starts calling the game engine Library running C + + to run the game.