From b91e64f9135cbb7705d443a8af23832d01b4bfe2 Mon Sep 17 00:00:00 2001 From: Ted Date: Thu, 18 Jul 2024 14:17:33 -0400 Subject: [PATCH] More NDK libs: add native_app_glue cc_library and example for android/log.h (#73) Should help with #55. --- BUILD.ndk_root.tpl | 20 ++++++++++++++++++++ examples/basic/java/com/app/BUILD | 1 + examples/basic/java/com/app/jni_dep.cc | 1 + examples/basic/java/com/app/jni_dep.h | 1 + 4 files changed, 23 insertions(+) diff --git a/BUILD.ndk_root.tpl b/BUILD.ndk_root.tpl index 2ed0917..a8c6d47 100644 --- a/BUILD.ndk_root.tpl +++ b/BUILD.ndk_root.tpl @@ -36,3 +36,23 @@ cc_library( ]), linkopts = ["-ldl"], ) + +# NOTE: New projects should use GameActivity instead. +# https://developer.android.com/games/agdk/game-activity +cc_library( + name = "native_app_glue", + srcs = glob([ + "sources/android/native_app_glue/*.c", + # TODO(#32): Remove this hack + "ndk/sources/android/native_app_glue/*.c", + ]), + hdrs = glob([ + "sources/android/native_app_glue/*.h", + # TODO(#32): Remove this hack + "ndk/sources/android/native_app_glue/*.h", + ]), +) + +exports_files ([ + "sources/android/native_app_glue/android_native_app_glue.h", +]) diff --git a/examples/basic/java/com/app/BUILD b/examples/basic/java/com/app/BUILD index e6f3f3a..9db25b7 100644 --- a/examples/basic/java/com/app/BUILD +++ b/examples/basic/java/com/app/BUILD @@ -31,4 +31,5 @@ cc_library( name = "jni_dep", srcs = ["jni_dep.cc"], hdrs = ["jni_dep.h"], + linkopts = ["-llog"], ) diff --git a/examples/basic/java/com/app/jni_dep.cc b/examples/basic/java/com/app/jni_dep.cc index 366c4c0..7b288fe 100644 --- a/examples/basic/java/com/app/jni_dep.cc +++ b/examples/basic/java/com/app/jni_dep.cc @@ -15,5 +15,6 @@ #include "java/com/app/jni_dep.h" int calculate(int a, int b) { + __android_log_write(3, "MyTag", "foobar"); return a + b * 20; } diff --git a/examples/basic/java/com/app/jni_dep.h b/examples/basic/java/com/app/jni_dep.h index 342551c..139001c 100644 --- a/examples/basic/java/com/app/jni_dep.h +++ b/examples/basic/java/com/app/jni_dep.h @@ -13,5 +13,6 @@ // limitations under the License. #pragma once +#include int calculate(int a, int b);