Skip to content

ADFA-1079 | Add Native Logging Demos template bundle (C and C++) - #143

Open
jimturner-adfa wants to merge 3 commits into
mainfrom
feature/ADFA-1079-native-logging-demos
Open

jimturner-adfa wants to merge 3 commits into
mainfrom
feature/ADFA-1079-native-logging-demos

Conversation

@jimturner-adfa

@jimturner-adfa jimturner-adfa commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

ADFA-1079

Adds templates/Native-Logging-Demos, a template bundle with two projects that write to Code on the Go's App Logs window from native code. Each has one button that calls runDemo() over JNI. Kotlin or Java for the activity.

Template Shows
Native Log Demo (C) C11: LOGx macros over __android_log_print, __android_log_write, a __android_log_vprint wrapper, a printf-checked helper adding __func__/__LINE__, errno reporting, a pthread worker
Native Log Demo (C++) C++17: type-safe logx::info() << ... logger, RAII scope timer, structured bindings, a custom type with operator<<, an exception's what(), a std::thread worker

Review by commit

  1. 877c043 - verbatim copy of EmptyActivity from core.cgt into both templates. Skim.
  2. a7abde9 - the demos: native sources, CMake, externalNativeBuild, layout, strings, metadata, gallery page, icons.
  3. 5299df6 - gallery page names the screen Add-ons Manager, as the app labels it.

Design choices

  • RegisterNatives in JNI_OnLoad instead of Java_<package>_... names. Those need _1 mangling for a package containing _, which a template cannot apply (the NDK-Installer template has this bug). Rejected: documenting "no underscores in the package".
  • No ANDROID_LOG_FATAL - App Logs does not recognise F and shows the line as raw text.
  • Requires the NDK-Installer plugin; ndkVersion = "29.0.14206865" and arm64-v8a match what it installs.
  • Skeleton is core's Empty Activity, not the NDK-Installer template, which carries Compose/cruft config.

Testing

On a Pixel 6 Pro (arm64, API 37), Code on the Go C-d-1014-1359, NDK-Installer plugin installed:

  • Installed the .cgt via Add-ons Manager; the dialog lists both templates in order.
  • Generated C++/Kotlin (com.example.native_log_cpp) and C/Java (com.example.native_log_c): no .peb suffixes, no template/ dir, other language dropped.
  • Both build with the on-device Gradle + CMake, install and launch (JNI_OnLoad registration works with the underscore packages).
  • After tapping the button, every demo line (V-E levels, formatted values, errno / exception, worker thread on its own TID, timer) appears in App Logs with level colours; the tag filter isolates them and the Verbose chip hides the V line.
  • Font scale 1.0 and 2.0: no clipping, button and status reachable, system bars untouched, status text survives the recreate.
  • Host: both sources compile with NDK r29 at -Wall -Wextra -Wpedantic -Werror for API 21/26/35; all four template x language combinations build debug and release offline, and release keeps runDemo through R8.
  • addons check passes; build-templates.sh Native-Logging-Demos builds.

Observed, not caused by this PR: on one of the two runs App Logs omitted the app's first ~0.5 s of output (including the demo's Library loaded line), which was present in logcat. Likely a timing issue in LogSender's first delivery.

🤖 Generated with Claude Code

yaturner and others added 3 commits October 19, 2026 09:13
Verbatim copy of EmptyActivity from core.cgt into NativeLogDemoC and
NativeLogDemoCpp, no changes. The next commit turns both into the demos,
so its diff shows only what they add.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Two templates that show how to write to the App Logs window from native
code. Each has one button that calls runDemo() over JNI.

- Native Log Demo (C): C11. LOGx macros over __android_log_print,
  __android_log_write, a __android_log_vprint wrapper, a printf-checked
  helper that adds __func__/__LINE__, errno reporting, a pthread worker.
- Native Log Demo (C++): C++17. A type-safe operator<< logger, an RAII
  scope timer, structured bindings, a custom type with a stream operator,
  an exception's what(), a std::thread worker.

Natives are bound with RegisterNatives in JNI_OnLoad rather than
Java_<package>_ names, which break for a package containing '_'. FATAL
is left out because App Logs does not parse the F level. Both need the
NDK-Installer plugin; ndkVersion and arm64-v8a match what it installs.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The gallery page said Extensions Manager; the current build labels the
screen Add-ons Manager.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants