Entanglement between Android and C + +

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.