跪拜 Guibai
← All articles
Android

How to Build Tencent's Mars XLog from Source for 16K Alignment and Custom Log Formats

By 李斯维 ·
Read original on juejin.cn ↗ Google Translate ↗ Alt translation

Android's requirement for 16 KB page alignment breaks prebuilt native libraries that haven't been recompiled. Building XLog from the latest branch fixes that incompatibility and unlocks log-format customization that the frozen release never exposed.

Summary

The official Mars XLog release is stuck on version 1.3.0, missing 16K page alignment for .so files and offering no way to customize log output. The repository's `release/android/2024-t2.1` branch, however, contains recent commits and can be built successfully with NDK r29, Python 3.14, and CMake 4.2. Three build-script edits fix stale NDK paths, suppress deprecation warnings that new CMake treats as errors, and remove three unresolvable symbols from the linker export file.

Once compiled, the resulting `mars_xlog_sdk` module drops directly into an Android project as a library or an AAR. The real payoff of a source build is the ability to edit the log header, per-line prefix, and console output format by modifying `appender.cc`, `formater.cc`, and `ConsoleLog.cc` respectively. The walkthrough includes the exact ProGuard rules needed to keep the JNI layer intact.

Takeaways
NDK r29, Python 3.14.4, and CMake 4.2.3 on Ubuntu 26.04 via WSL2 form the working toolchain.
Three edits to `build_android.py` update the paths for `libc++_shared.so` and `llvm-strip`, and remove a broken string-formatting call in the strip command.
Adding `-DCMAKE_CXX_FLAGS="-Wno-error"` to the build command and suppressing deprecated-builtins/declarations warnings in `CMakeExtraFlags.txt` prevents new CMake from aborting on old code patterns.
Deleting `__xlogger_Print_impl`, `_Z22appender_set_console_logb`, and `_Z24appender_set_console_logb` from `export.exp` avoids undefined-symbol linker errors.
The compiled output lands in `mars_xlog_sdk/` as a ready-to-use Android library module with `libmarsxlog.so` and `libc++_shared.so` for armeabi-v7a and arm64-v8a.
Log headers are controlled in `appender.cc`, per-line prefixes in `formater.cc`, and console output formatting in `ConsoleLog.cc`.
ProGuard rules must keep `com.tencent.mars.**` and `com.tencent.mars.xlog.**`, plus all native methods, and wrapper modules need `consumer-rules` to retain their own package names.
Conclusions

Mars XLog remains a viable high-performance logger despite its abandoned release page; the active branch shows that internal maintenance continued inside WeChat.

Most build failures when reviving old C++ Android libraries trace to three predictable issues: NDK path drift, stricter compiler warnings in modern CMake, and stale symbol exports.

Customizing log formats at the native layer is a rare capability that most logging libraries don't expose, making a source build of XLog unusually valuable for teams with specific log-pipeline requirements.

Concepts & terms
16K page alignment
Android 15 and later require native libraries to be aligned to 16 KB memory pages instead of the traditional 4 KB. Prebuilt .so files compiled without this alignment will fail to load on devices that enforce it.
export.exp
A linker export map that controls which symbols are visible in a shared library. Removing stale symbols prevents undefined-reference errors when the underlying implementations have changed or been removed.
Source: juejin.cn ↗ Google Translate ↗ Backup ↗