In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-08 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article shows you how to use JNI and Crash to achieve positioning in Android. The content is concise and easy to understand. It will definitely brighten your eyes. I hope you can get something through the detailed introduction of this article.
1. For cooking without rice in Qiaowu, find the so library file without strip and complete symbol table.
In Android Studio 3.2.1:
The directory where the files before strip are located:
App/build/intermediaters/transforms/mergejniLibs/debug
Or choose according to whether the APP of Crash is debug or release version
App/build/intermediates/cmake/debug/obj or app/build/intermediates/cmake/release/obj
If you rely on Native module or aar, then
The directory where the files before strip are located:
YourNativeLibModule/build/intermediates/transforms/mergeJniLibs/debug
Due to the configuration of CMake/CXX_FLAGS and other reasons, the files in the above directory may still be strip. How to accurately judge whether so has been strip or not, please refer to the readelf tool mentioned below.
If you find that so is strip, try to add the following configuration to CMake:
# these lines of code indicate that the debug version of the so file retains the so reserved symbol library, which will cause the so file to be very large. # if you want the release version to keep the symbol library file, replace it with CMAKE_C_FLAGS_RELEASE and CMAKE_CXX_FLAGS_RELEASE#, but be sure to remove the-g option configured by release when it is officially released to the public. In order to avoid adding files sizeset (CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG}-g") set (CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG}-g") # NDK before R16 adds-g by default, the new version is uncertain, so you need a non-strip so file. It is best to configure-g in CMake.
The directory where the files after strip are located:
App/build/intermediaters/transforms/stripDebugSymbol/debug
two。 To beat a snake, you need to hit seven inches to determine the CPU architecture corresponding to the device where Crash occurs.
In JNI Crash's journal.
If there is a lib/arm, it is the armeabi-v7a architecture
If there is a lib/arm64, it is the arm64-v8a architecture
Then find the corresponding toolchain according to the CPU architecture:
Arm64-v8a corresponds to aarch74-linux-android-4.9.
Armeabi-v7a corresponds to arm-linux-androideabi-4.9.
4. If you want to do a good job, you must sharpen its tools. Use tools such as add2line and ndk-stack to analyze the log of JNI Crash.
Addr2line
The function is to find the file name and line number of the corresponding error code according to the memory address.
The directory is the bin folder of toolchain
For example, the bin folder corresponding to aarch74-linux-android-4.9 is
/ Android/Sdk/ndk-bundle/toolchains/aarch74-linux-android-4.9/prebuilt/linux-x86_64/bin
Arm-linux-androideabi-4.9, the corresponding bin folder is
/ media/kyle/a393d005-ebe5-42a0-8c6a-c86fdfb185c1/Android/Sdk/ndk-bundle/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin
Usage:
#-f indicates the name of the display function, and-e indicates execution, followed by the file containing the symbol library and the memory address reported (that is, the field after pc in Crash log) arm-linux-androideabi-addr2line-f-e xxx.so 0x8eb09258
Ndk-stack
The function is to generate a more readable Crash log with one click
The directory is
/ media/kyle/a393d005-ebe5-42a0-8c6a-c86fdfb185c1/Android/Sdk/ndk-bundle/ndk-stack
Usage:
#-sym indicates the abi directory corresponding to symbolsndk-stack-sym App/build/intermediates/transforms/mergeJniLibs/release/0/lib/-dump jniCrash.log
Or
Adb logcat | abi directory corresponding to ndk-stack-sym App/build/intermediates/transforms/mergeJniLibs/release/0/lib/
-delimiter-
Other tools supplement
Under toolchain:
Arm-linux-androideabi-readelf
1. Sometimes using addr2line to find that the function name can be displayed, but the line number is garbled. It may be because this so has been strip. By strip's so.
The number of "section headers" in the readelf result will be less than that after the non-strip, so we can judge whether the so is really strip according to the readelf.
Command format:
Arm-linux-androideabi-readelf-S xx.so
two。 Can be used to view all the functions in the so file. So if you encounter an error that cannot be found in the JNI method, you can use the tool to look at all the functions in the so library, and then search the corresponding JNI method to see if it has been compiled into the dynamic library.
Command format:
Arm-linux-androideabi-readelf-a xx.so > fun.txt # Note: you still need to use the so file before strip. The above command will write the result to fun.txt.
Arm-linux-androideabi-objdump
You can get the symbol table information of the so file, and you can see all the compiled methods and the address of the call stack.
Command format:
Arm-linux-androideabi-objdump-dx xx.so > stacktrace.txt or aarch74-linux-android-objdump-dx xx.so > stacktrace.txt
Arm-linux-androideabi-nm
You can view the symbols in the static library, such as the declaration of all methods.
If you encounter an error of type undefined reference while compiling a so dynamic library with a static library, or
Duplicated reference, you can use this instruction to export all the methods corresponding to the static library, and then see if there is a method
Command format:
Arm-linux-androideabi-nm xx.a > symbol.txt
The meaning of common semaphores:
# define SIGABRT 6 / / abort () calls the signal generated by the abort function, indicating that the program was aborted abnormally. The address corresponding to the # define SIGSEGV 11 / / segmentation violation pointer is invalid or illegal, such as access to out-of-bounds / stack overflow/ file operations are not allowed (fault addr 0x0 is generally a null pointer error) # define SIGILL 4 / / Illegal instruction executed illegal instructions, such as the compatibility of third-party libraries. Permission problem # define SIGSYS 31 / / illegal system call # define SIGBUS 7 / / illegal address, including memory address alignment error, such as accessing a 4-byte integer, but its address is not a multiple of 4. # define SIGFPE 8 / / the process performed an incorrect arithmetic operation, such as division 0, overflow # define SIGKILL 9 / / forced termination program. This signal can not be captured # define SIGPIPE 13 / / write on a pipe with no one to read it pipeline rupture, usually in inter-process communication to produce the above content is how to use JNI and Crash to achieve location in Android, have you learned the knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.