Single-step debugging and log printing of the JNI program in Android Studio, androidjni

Source: Internet
Author: User

Single-step debugging and log printing of the JNI program in Android Studio, androidjni

Recently, an algorithm (collision detection) needs to be implemented in C ++ to share the same program in IOS and ANDROID.


The following describes some things that android has encountered when calling this program. (Some Related Articles are searched online in the process, most of which are about tutorials in the eclipse environment. Therefore, it is necessary to write this article so that you do not forget it and make a detour)
The algorithm has been completed. The next natural process is to debug the program in one step and print logs. My IDE environment: Android Studio 1.5.1, ndk is the android-ndk-r10e. First, how to set the ndk directory, how to put the. h and. cpp files in the project, How to Write similar
JNIEXPORT jboolean JNICALL Java_com_example_shenzhigang_collisiondetection_Peng_isCollided
Such code, and so on. There are many tutorials on the Internet and will not be described. Support for One-Step debugging: Step 1: Open the build. gradle file of the module and add code similar to the following to the defaultConfig node.
ndk {
moduleName "HelloJNI"
stl "stlport_static"
ldLibs "log"
}
LdLibs "log" here will be mentioned later, moduleName "HelloJNI" Here HelloJNI only needs
System.loadLibrary("HelloJNI");
Here, we can. Step 2: Add the following code to buildTypes (also the file in step 1)
debug {
jniDebuggable true
}
 

Step 3: Synchronize the build. gradle file. If there are no red forks in the icons, select app-native. DEBUG now .....

========================================================== ========================================================== ==================== The following describes how to output logs in the jni program. Here is the difference between android studio and eclipse. It is also the main purpose of my article: Step 1: Open the build. gradle file of the module and add the following code to the ndk node under defaultConfig.
    ldLibs "log"
By the way, in eclipse, you can directly modify the Android. mk file and add Code such as LOCAL_LDLIBS: =-L $ (SYSROOT)/usr/lib-llog. Although android studio will eventually generate the Android. mk file, if this file is modified, it will be automatically overwritten every build. Step 2: This step is the same as that in eclipse. Under the file that needs to print logs,
#include <android/log.h>
Use the _ android_log_print function.

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.