Skip to content

Commit c0c80ce

Browse files
Dan AlbertDanAlbert
authored andcommitted
Simplify native_app_glue uses.
These should all just move to GameActivity, but that's a slightly more involved migration. This is an easy first step to clean up the existing callers.
1 parent 5dd0e38 commit c0c80ce

File tree

3 files changed

+13
-32
lines changed

3 files changed

+13
-32
lines changed

camera/basic/src/main/cpp/CMakeLists.txt

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,10 @@ cmake_minimum_required(VERSION 3.22.1)
1818
project(CameraBasic LANGUAGES C CXX)
1919

2020
include(AppLibrary)
21+
include(AndroidNdkModules)
2122
find_package(camera-utils REQUIRED CONFIG)
2223

23-
include_directories(${ANDROID_NDK}/sources/android/native_app_glue)
24-
25-
add_library(app_glue STATIC
26-
${ANDROID_NDK}/sources/android/native_app_glue/android_native_app_glue.c)
27-
28-
# Export ANativeActivity_onCreate(),
29-
# Refer to: https://github.com/android-ndk/ndk/issues/381.
30-
set(CMAKE_SHARED_LINKER_FLAGS
31-
"${CMAKE_SHARED_LINKER_FLAGS} -u ANativeActivity_onCreate")
24+
android_ndk_import_module_native_app_glue()
3225

3326
add_app_library(ndk_camera SHARED
3427
${CMAKE_CURRENT_SOURCE_DIR}/android_main.cpp
@@ -39,12 +32,13 @@ add_app_library(ndk_camera SHARED
3932
${CMAKE_CURRENT_SOURCE_DIR}/camera_ui.cpp
4033
)
4134

42-
# add lib dependencies
4335
target_link_libraries(ndk_camera
36+
PRIVATE
4437
camera-utils::camera-utils
4538
android
4639
log
4740
m
48-
app_glue
41+
$<LINK_LIBRARY:WHOLE_ARCHIVE,native_app_glue>
4942
camera2ndk
50-
mediandk)
43+
mediandk
44+
)

endless-tunnel/app/src/main/cpp/CMakeLists.txt

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,9 @@ cmake_minimum_required(VERSION 3.22.1)
1818
project(EndlessTunnel LANGUAGES C CXX)
1919

2020
include(AppLibrary)
21+
include(AndroidNdkModules)
2122

22-
# build native_app_glue as a static lib
23-
add_library(native_app_glue STATIC
24-
${ANDROID_NDK}/sources/android/native_app_glue/android_native_app_glue.c
25-
)
26-
27-
# Export ANativeActivity_onCreate(),
28-
# Refer to: https://github.com/android-ndk/ndk/issues/381.
29-
set(CMAKE_SHARED_LINKER_FLAGS
30-
"${CMAKE_SHARED_LINKER_FLAGS} -u ANativeActivity_onCreate")
23+
android_ndk_import_module_native_app_glue()
3124

3225
# Set common compiler options
3326
add_definitions("-DGLM_FORCE_SIZE_T_LENGTH -DGLM_FORCE_RADIANS")
@@ -63,26 +56,25 @@ add_app_library(game SHARED
6356
welcome_scene.cpp
6457
)
6558

66-
if (ANDROID_ABI STREQUAL riscv64)
59+
if(ANDROID_ABI STREQUAL riscv64)
6760
# This sample uses OpenSLES, which was deprecated in API 26. Our
6861
# minSdkVersion is 21, but we also build for riscv64, which isn't a
6962
# supported ABI yet and so that configuration is built for the latest API
7063
# level supported by the NDK.
7164
#
7265
# Longer term, this sample should migrate to Oboe.
7366
target_compile_options(game PRIVATE -Wno-deprecated-declarations)
74-
endif ()
67+
endif()
7568

7669
target_include_directories(game PRIVATE
7770
${CMAKE_CURRENT_SOURCE_DIR}
7871
${CMAKE_CURRENT_SOURCE_DIR}/data
79-
${ANDROID_NDK}/sources/android/native_app_glue
8072
)
8173

8274
# add lib dependencies
8375
target_link_libraries(game
8476
android
85-
native_app_glue
77+
$<LINK_LIBRARY:WHOLE_ARCHIVE,native_app_glue>
8678
atomic
8779
EGL
8880
GLESv2

native-activity/app/src/main/cpp/CMakeLists.txt

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,12 @@ cmake_minimum_required(VERSION 4.1.0)
1818
project(NativeActivity LANGUAGES C CXX)
1919

2020
include(AppLibrary)
21+
include(AndroidNdkModules)
2122

22-
add_library(native_app_glue STATIC
23-
${ANDROID_NDK}/sources/android/native_app_glue/android_native_app_glue.c
24-
)
23+
android_ndk_import_module_native_app_glue()
2524

2625
add_app_library(native-activity SHARED main.cpp)
2726

28-
target_include_directories(native-activity PRIVATE
29-
${ANDROID_NDK}/sources/android/native_app_glue
30-
)
31-
3227
target_link_libraries(native-activity
3328
android
3429
$<LINK_LIBRARY:WHOLE_ARCHIVE,native_app_glue>

0 commit comments

Comments
 (0)