i do first steps in developing for Native Android and need some help. I copy armv7 gdbserver to my phone and compile "hello word" test app written with C++. And now i want to debug my app with gdb from android ndk package.
I start gdb and connect to phone by target remote command and get this messages and after "s" command gdb holds.
(gdb) target remote 192.168.1.157:1235
Remote debugging using 192.168.1.157:1235
Reading /data/local/Test from remote target...
warning: File transfers from remote targets can be slow. Use "set sysroot" to access files locally instead.
Reading /data/local/Test from remote target...
Reading symbols from target:/data/local/Test...done.
Reading /system/bin/linker from remote target...
Reading /system/bin/linker from remote target...
Reading symbols from target:/system/bin/linker...(no debugging symbols found)...done.
0xb6fdf654 in __dl__start () from target:/system/bin/linker
(gdb) s
Single stepping until exit from function __dl__start,
which has no line number information.
What i'm doing wrong? Why it holds? And how generate symbols/debug info? I tried to set "set(CMAKE_BUILD_TYPE Debug)" but no new files were generated.
My CmakeLists.Txt
set(PROJECT_NAME Test)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_TOOLCHAIN_FILE android-cmake/android.toolchain.cmake)
set(ANDROID_NDK /home/drem1lin/Android/Sdk/ndk-bundle)
set(ANDROID_NATIVE_API_LEVEL "android-19")
set(ANDROID_TOOLCHAIN_NAME "arm-linux-androideabi-4.9")
set(ANDROID_ABI "armeabi-v7a")
project(${PROJECT_NAME})
cmake_minimum_required(VERSION 3.1)
include_directories(include)
file(GLOB SOURCES source/*.c*)
add_executable(${PROJECT_NAME} ${SOURCES})
foreach (module_src ${MODULES})
get_filename_component(module ${module_src} NAME_WE)
string(TOLOWER ${module} module)
add_library(${module} SHARED ${module_src})
set_target_properties(${module} PROPERTIES PREFIX "")
set_target_properties(${module} PROPERTIES SUFFIX ".m")
target_link_libraries(${module} ${LIBRARY_DEPS})
endforeach(module_src)
With best regards Paul.
For those who uses the new NDK toolchain (not using Android.mk
but add sections like externalNativeBuild
in build.gradle
), here is the steps:
Step1: Change build.gradle
as follows.
NOTE: If your ndk is used in a library, then change your library's gradle file instead of your main application's.
android {
defaultConfig {
packagingOptions {
doNotStrip '**.so' // ADD THIS! #1
}
externalNativeBuild {
cmake {
cppFlags "-Wl,--build-id -g" // ADD THIS! #2
}
}
}
}
Step2: Build the project (for me it is flutter build apk --debug
, but for native Android projects you know it).
Step3: Now your .so
with symbols is here: (This is sample location, where the library name is vision_utils and my .so file name is libvision_utils.so)
./build/vision_utils/intermediates/cmake/debug/obj/arm64-v8a/libvision_utils.so
or
./build/vision_utils/intermediates/stripped_native_libs/debug/out/lib/arm64-v8a/libvision_utils.so
Bonus1: If you want the "actual" .so file in apk, find it like unzip -p ./build/app/outputs/apk/debug/app-debug.apk lib/arm64-v8a/libvision_utils.so > ./build/temp-libvision_utils.so
.
Bonus2: If you are using bloaty, you can run your command like: bloaty ./build/temp-libvision_utils.so --debug-file=./build/vision_utils/intermediates/stripped_native_libs/debug/out/lib/arm64-v8a/libvision_utils.so -d compileunits
I have this trouble because I know linux build system very bad. Executible with symbols was created in {project}/obj/local/armeabi/
folder
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With