diff --git a/CMakeLists.txt b/CMakeLists.txt index 8f94f13..138be47 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -45,6 +45,7 @@ elseif (ANDROID) set(SDL2TTF_FOUND 1) set(DEFAULT_FONT_PATH .) find_library(ndk_zlib z) + find_library(ndk_log log) else() include(TestBigEndian) TEST_BIG_ENDIAN(WORDS_BIGENDIAN) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 096fc0a..ff19e28 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -85,7 +85,7 @@ if (EMSCRIPTEN) elseif (ANDROID) - target_link_libraries(xsystem35 PRIVATE SDL2 SDL2_ttf SDL2_mixer ${ndk_zlib}) + target_link_libraries(xsystem35 PRIVATE SDL2 SDL2_ttf SDL2_mixer ${ndk_zlib} ${ndk_log}) else() # non-emscripten, non-android target_link_libraries(xsystem35 PRIVATE m ZLIB::ZLIB) diff --git a/src/xsystem35.c b/src/xsystem35.c index 9fcf2df..ad39007 100644 --- a/src/xsystem35.c +++ b/src/xsystem35.c @@ -49,6 +49,10 @@ #include #endif +#ifdef __ANDROID__ +#include +#endif + #include "nact.h" #include "portab.h" #include "xsystem35.h" @@ -192,32 +196,45 @@ static void sys35_usage(boolean verbose) { } void sys_message(char *format, ...) { + if (debuglv < sys_nextdebuglv) + return; + va_list args; - va_start(args, format); -#ifdef DEBUG - if (debuglv >= sys_nextdebuglv) { - if (sys_nextdebuglv >= 5) { - vfprintf(fpdebuglog, format, args); - fflush(fpdebuglog); - } else { - vfprintf(stderr, format, args); - } - } -#else - if (debuglv >= sys_nextdebuglv) { + +#ifdef __ANDROID__ + const int prio_table[] = { + ANDROID_LOG_FATAL, + ANDROID_LOG_ERROR, + ANDROID_LOG_WARN, + ANDROID_LOG_INFO, + ANDROID_LOG_INFO, + ANDROID_LOG_VERBOSE, + }; + int prio = prio_table[min(sys_nextdebuglv, 5)]; + __android_log_vprint(prio, "xsystem35", format, args); +#elif defined (DEBUG) + if (sys_nextdebuglv >= 5) { + vfprintf(fpdebuglog, format, args); + fflush(fpdebuglog); + } else { vfprintf(stderr, format, args); } +#else + vfprintf(stderr, format, args); #endif va_end(args); - } void sys_error(char *format, ...) { va_list args; va_start(args, format); +#ifdef __ANDROID__ + __android_log_vprint(ANDROID_LOG_FATAL, "xsystem35", format, args); +#else vfprintf(stderr, format, args); +#endif va_end(args); sys35_remove(); exit(1);