Android Notes: C + + File Add Log method share _android

Source: Internet
Author: User
1. Add header File
Copy Code code as follows:

#include <utils/Log.h>
Or
#include <cutils/Log.h>

This is the time to print out the log using ALOGE/ALOGI/ALOGW and other methods
However, some places cannot be used in this way because it relies on libutils libctuils libraries
In the Mk file, see Add the following dependency compilation
Copy Code code as follows:

#LOCAL_MODULE: = ...
#base_intermediates: = $ (call Local-intermediates-dir)//Add below the line, this looks like a lookup dependency file
Local_shared_libraries + = \
Libutils libcutils
... ...
Include $ (build_shared_library)//above line, this is the start of compiling

2. The usual stack
Copy Code code as follows:

Android::callstack Stack;
Stack.update (1);
Stack.dump ("");

This need to add a header file, but to pay special attention to a problem, this head must be added to the end of all the head, or not use, especially to look at the Android source WebKit. The header files that need to be added are as follows:
Copy Code code as follows:

#include <utils/CallStack.h>

Today something, follow-up completion, if you have better, or special circumstances, welcome to recommend
3.c++ Alternative Stacks
This method is document controlled. You can achieve file control by reading and writing files in an Android device and then assigning null pointers to the file.
This method benefits as long as the C, C + + files can add this log, no dependencies, convenient! There is also a bad thing, log can only run to the place you add, because the collapse of the library, the back of the failed to run.
The implementation code is as follows:
Copy Code code as follows:

FILE *FP = NULL; Need to be aware
fp = fopen ("Data/test", "R");
if (NULL = fp)
{
return false; Used when return value is required
} esle {
Fclose (FP);
int *FP = NULL;
*FP = 100; Null pointer assignment error, demo it's wrong.
return false; Used when return value is required
}

The general collapse of the library is not see the stack, we can use disassembly to view the specific stack.
There are two sets of libraries compiled in Android: a set of unsigned, can't be viewed, and the other one is signed, and that's what we're looking at.
After the signed compilation is in the path (\out\target\product\generic\symbols\system\lib)
The disassembly tool with arm in Android can be used normally after setting up the build environment, and commands are as follows:
Copy Code code as follows:

Arm-eabi-addr2line-f-E **.so address 1 address 2 ... ... 

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.