Let's start small, how to tie Android NDK to C::B
There are two ways:
- register on each platform its profile, with executable files according to the platform. In my opinion it is tiring, a lot of things and it is not clear why. Given that if you collect the same for all platforms, the volume of gestures with switching configurations is quite large. My default are
arm64-v8a, armeabi-v7a, x86, x86_64 .
- use the native build system
ndk-build . This is the simplest and most elegant solution that does not conflict with most of the C::B checks, but in the C::B settings every detail is important, the scheme is quite capricious, and with inaccuracies it can easily break.
Android NDK Integration
The ideology and manner of building an application using the Android NDK toolchain is as close as possible to the typical C::B behavior, the process logic:
assembly in Release mode - stages: always a new assembly of the application, copying it to the device, launching the application. All actions are displayed in the console C::B
build in Debug mode - stages: always a new build of the application, copying it to the device, copying NDK-парт files for debugging gdbserver , gdb.setup , running gdbserver on the device, waiting for the GDB debugger to connect for debugging.
запуска приложения mode - stages: launching an application on a device with outputting results to the console.
Отладка -> Старт mode Отладка -> Старт - stages: always a new build of the application, copying it to the device, copying NDK-парт files for debugging gdbserv , gdb.setup , running gdbserv on the device, automatically connecting the debugger GDB and switching to debug mode.
in the Debug , Отладка -> Старт modes, the window started by gdbserver starts in a minimized state and automatically closes when debugging is completed.
Template files:
Project C::B , important sections:
<Build><Option output> - points to the script of the remote launch of the application on the device - RunRemote.cmd . The script is generated automatically.<Build><Option compiler="android_ndk-build"> is the processed name of the compiler in the C::B settings - Android NDK-Build . How to create a new compiler account is shown below.
The <Extensions><debugger><remote_debugging> contains settings for remote debugging implemented using GDB :
options ip_address="127.0.0.1" ip_port="59999" extended_remote="0" , if there is a need to change the port number, then this must also be done in the Makefile . If the extended_remote option is nonzero, the remotely running gdbserver window will not close automatically after debugging.
AndroidNdkTemplate.cbp - C::B project file:
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?> <CodeBlocks_project_file> <FileVersion major="1" minor="6" /> <Project> <Option title="C::B Android Ndk project Template" /> <Option makefile_is_custom="1" /> <Option pch_mode="2" /> <Option compiler="android_ndk-build" /> <Option check_files="0" /> <Build> <Target title="Release"> <Option output="RunRemote.cmd" prefix_auto="0" extension_auto="0" /> <Option type="1" /> <Option compiler="android_ndk-build" /> </Target> <Target title="Debug"> <Option output="RunRemote.cmd" prefix_auto="0" extension_auto="0" /> <Option type="1" /> <Option compiler="android_ndk-build" /> </Target> </Build> <Compiler> <Add option="-Wall" /> </Compiler> <Unit filename="main.c"> <Option compilerVar="CC" /> </Unit> <Extensions> <code_completion /> <envvars /> <debugger> <search_path add="obj/local/armeabi-v7a" /> <search_path add="obj/local/arm64-v8a" /> <search_path add="obj/local/x86" /> <search_path add="obj/local/x86_64" /> <remote_debugging target="Debug"> <options conn_type="0" serial_baud="115200" ip_address="127.0.0.1" ip_port="59999" additional_cmds_before="set solib-search-path obj/local/armeabi-v7a
file obj/local/armeabi-v7a/hello_world
" /> </remote_debugging> </debugger> </Extensions> </Project> </CodeBlocks_project_file>
Source control files for the build in the NDK project directory:
Application.mk - setting build parameters:
APP_ABI := all APP_STL := c++_static APP_OPTIM := debug APP_PLATFORM := android-22 APP_BUILD_SCRIPT := Android.mk
Android.mk is actually a make-file unique for each NDK project (application):
LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) LOCAL_MODULE := hello_world LOCAL_SRC_FILES := ./main.c LOCAL_C_INCLUDES := ./ LOCAL_LDLIBS := -llog include $(BUILD_EXECUTABLE)
Makefile - directly started C::B :
PLATFORM := armeabi-v7a NDKROOT := C:\__BuildSource\__LIB__\android-ndk-r20-beta2 PROJECT := $(dir $(abspath $(lastword $(MAKEFILE_LIST)))) BUILDTAG := $(filter-out $@,$(MAKECMDGOALS)) BUILDOPT := include Application.mk include $(APP_BUILD_SCRIPT) ifneq ($(APP_ABI),all) PLATFORM = $(APP_ABI) endif ifeq ($(BUILDTAG),Debug) BUILDOPT = V=1 NDK_DEBUG=1 else BUILDOPT = -j 4 endif all: allndk Debug: allndk adbsetup adbdebug buildscript rundebug Release: allndk adbsetup adbexec buildscript cleanDebug: clean cleanRelease: clean cleanall: clean allndk: @echo '==== Build $(BUILDTAG) -> $(APP_ABI) platform -> active device: [ $(PLATFORM) ] ====' @Cmd.exe /C $(NDKROOT)\ndk-build.cmd NDK_APPLICATION_MK=$(PROJECT)Application.mk NDK_PROJECT_PATH=$(PROJECT) $(BUILDOPT) clean: @echo '==== Clean ====' @Cmd.exe /C $(NDKROOT)\ndk-build.cmd NDK_APPLICATION_MK=$(PROJECT)Application.mk NDK_PROJECT_PATH=$(PROJECT) clean @Cmd.exe /C adb.exe shell rm -f /data/local/tmp/$(LOCAL_MODULE) adbsetup: @echo '==== ADB SETUP: [ $(PLATFORM) ] ====' @Cmd.exe /C adb.exe push $(PROJECT)libs\$(PLATFORM)\$(LOCAL_MODULE) /data/local/tmp/$(LOCAL_MODULE) @Cmd.exe /C adb.exe shell /system/bin/chmod 0777 /data/local/tmp/$(LOCAL_MODULE) adbexec: @echo '==== ADB RUN: [ $(PLATFORM) ] ====' @Cmd.exe /C adb.exe shell /data/local/tmp/$(LOCAL_MODULE) adbdebug: @echo '==== GDB Debug: [ $(PLATFORM) ] ====' @Cmd.exe /C adb.exe push $(PROJECT)libs\$(PLATFORM)\gdb.setup /data/local/tmp/gdb.setup @Cmd.exe /C adb.exe push $(PROJECT)libs\$(PLATFORM)\gdbserver /data/local/tmp/gdbserver @Cmd.exe /C adb.exe shell /system/bin/chmod 0777 /data/local/tmp/gdbserver rundebug: @Cmd.exe /C DebugRemote.cmd buildscript: ifeq (,$(wildcard ./RunRemote.cmd)) @echo "adb.exe shell /data/local/tmp/$(LOCAL_MODULE)" >RunRemote.cmd endif ifeq (,$(wildcard ./DebugRemote.cmd)) @echo "adb.exe forward tcp:59999 tcp:59999" >DebugRemote.cmd @echo "start \"$(PLATFORM) GDB server\" /MIN adb.exe shell /data/local/tmp/gdbserver :59999 /data/local/tmp/$(LOCAL_MODULE)" >>DebugRemote.cmd @echo "exit" >>DebugRemote.cmd endif .PHONY: clean all
The Application.mk and Makefile files are universal for all projects collected using the NDK and do not require revisions.
To understand the structure where what lies in the project of the NDK application, I will give a tree:
│ Android.mk │ AndroidNdkTemplate.cbp │ Application.mk │ main.c │ Makefile │ ├───libs │ ├───arm64-v8a │ │ gdb.setup │ │ gdbserver │ │ hello_world │ ├───armeabi-v7a │ │ gdb.setup │ │ gdbserver │ │ hello_world │ ├───x86 │ │ gdb.setup │ │ gdbserver │ │ hello_world │ └───x86_64 │ gdb.setup │ gdbserver │ hello_world │ └───obj └───local ├───arm64-v8a │ │ hello_world │ ├───objs │ │ └───hello_world │ └───objs-debug │ └───hello_world │ main.o │ main.od ├───armeabi-v7a │ │ hello_world │ │ │ ├───objs │ │ └───hello_world │ └───objs-debug │ └───hello_world │ main.o │ main.od ├───x86 │ │ hello_world │ │ │ ├───objs │ │ └───hello_world │ └───objs-debug │ └───hello_world │ main.o │ main.od └───x86_64 │ hello_world │ ├───objs │ └───hello_world └───objs-debug └───hello_world main.o main.od
View of project settings from GUI C::B :




Be sure to indicate the possible paths where the object files with debugging symbols are located:
obj/local/armeabi-v7a
obj/local//arm64-v8a
obj/local/x86
obj/local/x86_64

You need to add GDB commands that convey information about the finding of debugging symbols for the platform of the connected device:
set solib-search-path obj/local/armeabi-v7a - location of debug symbols for active device.file obj/local/armeabi-v7a/<имя приложения> is the name of the application being debugged.
Type of compiler settings in C::B :



Additional debug menu of the NDK application:
Both scripts used in the menu have a fixed name and are automatically generated during the execution of the Makefile , for convenience, it is reasonable to add them to the menu:


The debugging method of the application consists of standard actions, for example, through F8 or the Отладка -> Старт menu. As soon as the debugger is launched, you need to call the ADB Debug Remote server item from the created menu; with this command you will start the GDB сервер on the device that will launch your application. You connect to the GDB серверу remotely and can conduct a debugging session.
In Debug mode, the remote server is started automatically and does not require calling this menu item.
See the screenshot of the debugger settings in the project above.
This debugger startup scheme supports non-rooted devices.
The global debugger settings for NDK look like this:

Debug on device:

The result of assembling an application with NDK :

Benefits of using NDK:
Unlike static builds for a specific platform:
You do not need to compile binary files statically, so the size of the output binary file will be smaller.
You can use android C/C++ libraries, such as liblog, to be able to output to logcat from the application.
Possibilities of this solution:
no rooted device required
full assembly debugging, without additional tools (NDK tool kit)
full build in Debug/Release modes
full launch of the application (from the device)
auto start / stop gdbserver from device
no Gradle/Java code wrappers required, works directly with the device
The full code of the HOWTO NDK C::B template posted on github
wxWidgetsin Android,C::Bwritten in it, but this is not a reason to use this widget as a framework for your own code. - NewViewC::Bworks fine in a batch build in automatic mode, very convenient and easy to integrate. - NewViewC::BwithdevkitPSPis a useful overview, it may be useful to someone. - NewView