Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use LOG output for tracking in CumberCraft +

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

Today, I will talk to you about how to use LOG output for tracking in CAccord Candle +. Many people may not know much about it. In order to make you understand better, the editor has summarized the following content for you. I hope you can get something according to this article.

We often use Log.i in JAVA debugging for output tracking. In this article, I will mainly talk about how to achieve log output in C++ code in NDK development.

Realization method

Reference the android/ logh header file in the C++ file.

The _ _ android_log_print method in the header file is our log output method.

Assemble our _ _ android_log_print method through the macro definition of # define.

You can output directly where you want to output the log.

Code implementation

Let's still use the original Demo program and follow our implementation method.

Reference the android/ logh header file in the C++ file

We open the native-lib.cpp file and add the reference android/log.h at the top, as shown in the following figure

Assemble our _ _ android_log_print method through the macro definition of # define

The code is:

# define LOG_TAG "System.out" # define LOGI (...) _ _ android_log_print (ANDROID_LOG_INFO, LOG_TAG, _ _ VA_ARGS__)

You can output the log directly where you want to.

Let's take a look at the log output directly in the method of multiplying the two numbers in the previous chapter and modify it.

Extern "C" JNIEXPORT jint JNICALLJava_dem_vac_vaccaendk_MainActivity_plusFromJNI (JNIEnv * env, jobject instance, jint a, jint b) {

/ / first get class. The parameter jobject passed here represents Mainactivity, so we need to look for jclass jcls=env- > FindClass ("dem/vac/vaccaendk/VaccaeJNI"); if (jcls= = NULL) {return 0;}

/ / get method jmethodID jmethod= env- > GetMethodID (jcls, "Plus", "(II) I"); if (jmethod==NULL) {return 0;}

/ / output the passed an and b parameters LOGI ("a% d", a); LOGI ("baked% d", b)

/ / call access / / the first parameter is jobject, which is passed in jobject is Mainactivity, / / if you directly use the passed in CallIntMethod, there will be an error, because our / / method is in the class of VaccaeJNI, so we need to instantiate that class first, and then call jobject jobj = env- > AllocObject (jcls); jint retint = env- > CallIntMethod (jobj, jmethod, a, b)

/ / output the result LOGI ("result=%d", retint) obtained by calling the multiplication method

Return retint;}

Next, let's take a look at the results after running.

From the figure above, we can see that our output of each step has been output in the log of Logcat, so that we can find out which step of the problem can be found through the output in debugging the code of CCompact +, which is convenient for us to develop and improve efficiency.

After reading the above, do you have any further understanding of how to use the LOG output for tracking in CCompact +? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report