From 126a9cec067272346d5b2897ca42e3f23c2610ce Mon Sep 17 00:00:00 2001 From: "L. E. Segovia" Date: Thu, 2 May 2024 00:15:10 +0000 Subject: [PATCH] android: Port over to the CMake Cerbero SDK module Also ensure the library's exports are properly declared, instead of relying on `-fvisibility=default` implicitly. Part-of: --- .../android/android-tutorial-1/.gitignore | 1 + .../android/android-tutorial-1/build.gradle | 8 ++-- .../android-tutorial-1/jni/CMakeLists.txt | 41 +++++++++++++++++ .../android-tutorial-1/jni/tutorial-1.c | 2 +- .../android/android-tutorial-2/.gitignore | 1 + .../android/android-tutorial-2/build.gradle | 10 ++--- .../android-tutorial-2/jni/CMakeLists.txt | 41 +++++++++++++++++ .../android-tutorial-2/jni/tutorial-2.c | 2 +- .../android/android-tutorial-3/.gitignore | 1 + .../android/android-tutorial-3/build.gradle | 10 ++--- .../android-tutorial-3/jni/CMakeLists.txt | 44 ++++++++++++++++++ .../android-tutorial-3/jni/tutorial-3.c | 2 +- .../android/android-tutorial-4/.gitignore | 1 + .../android/android-tutorial-4/build.gradle | 10 ++--- .../android-tutorial-4/jni/CMakeLists.txt | 45 +++++++++++++++++++ .../android-tutorial-4/jni/tutorial-4.c | 2 +- .../android/android-tutorial-5/.gitignore | 1 + .../android/android-tutorial-5/build.gradle | 10 ++--- .../android-tutorial-5/jni/CMakeLists.txt | 45 +++++++++++++++++++ .../android-tutorial-5/jni/tutorial-5.c | 2 +- 20 files changed, 250 insertions(+), 29 deletions(-) create mode 100644 subprojects/gst-docs/examples/tutorials/android/android-tutorial-1/jni/CMakeLists.txt create mode 100644 subprojects/gst-docs/examples/tutorials/android/android-tutorial-2/jni/CMakeLists.txt create mode 100644 subprojects/gst-docs/examples/tutorials/android/android-tutorial-3/jni/CMakeLists.txt create mode 100644 subprojects/gst-docs/examples/tutorials/android/android-tutorial-4/jni/CMakeLists.txt create mode 100644 subprojects/gst-docs/examples/tutorials/android/android-tutorial-5/jni/CMakeLists.txt diff --git a/subprojects/gst-docs/examples/tutorials/android/android-tutorial-1/.gitignore b/subprojects/gst-docs/examples/tutorials/android/android-tutorial-1/.gitignore index 09614d4230..443f6eb687 100644 --- a/subprojects/gst-docs/examples/tutorials/android/android-tutorial-1/.gitignore +++ b/subprojects/gst-docs/examples/tutorials/android/android-tutorial-1/.gitignore @@ -1,3 +1,4 @@ +.cxx/ .externalNativeBuild/ assets/ gst-android-build/ diff --git a/subprojects/gst-docs/examples/tutorials/android/android-tutorial-1/build.gradle b/subprojects/gst-docs/examples/tutorials/android/android-tutorial-1/build.gradle index 7eaa85924b..78434cc7da 100644 --- a/subprojects/gst-docs/examples/tutorials/android/android-tutorial-1/build.gradle +++ b/subprojects/gst-docs/examples/tutorials/android/android-tutorial-1/build.gradle @@ -12,7 +12,7 @@ android { externalNativeBuild { - ndkBuild { + cmake { def gstRoot if (project.hasProperty('gstAndroidRoot')) @@ -23,7 +23,7 @@ android { if (gstRoot == null) throw new GradleException('GSTREAMER_ROOT_ANDROID must be set, or "gstAndroidRoot" must be defined in your gradle.properties in the top level directory of the unpacked universal GStreamer Android binaries') - arguments "NDK_APPLICATION_MK=jni/Application.mk", "GSTREAMER_JAVA_SRC_DIR=src", "GSTREAMER_ROOT_ANDROID=$gstRoot", "GSTREAMER_ASSETS_DIR=src/assets" + arguments "-DCMAKE_BUILD_TYPE=Release", "-DANDROID_STL=c++_shared", "-DGSTREAMER_ROOT_ANDROID=$gstRoot" targets "tutorial-1" @@ -52,8 +52,8 @@ android { } externalNativeBuild { - ndkBuild { - path 'jni/Android.mk' + cmake { + path 'jni/CMakeLists.txt' } } ndkVersion '25.2.9519653' diff --git a/subprojects/gst-docs/examples/tutorials/android/android-tutorial-1/jni/CMakeLists.txt b/subprojects/gst-docs/examples/tutorials/android/android-tutorial-1/jni/CMakeLists.txt new file mode 100644 index 0000000000..879f4e3b45 --- /dev/null +++ b/subprojects/gst-docs/examples/tutorials/android/android-tutorial-1/jni/CMakeLists.txt @@ -0,0 +1,41 @@ +cmake_minimum_required(VERSION 3.18.1) + +project("android-tutorial-1" LANGUAGES C CXX) + +if(NOT DEFINED GSTREAMER_ROOT_ANDROID) + message(FATAL_ERROR "GSTREAMER_ROOT_ANDROID is not defined!") +endif() + +if(ANDROID_ABI STREQUAL "armeabi") + set(GSTREAMER_ROOT "${GSTREAMER_ROOT_ANDROID}/arm") +elseif(ANDROID_ABI STREQUAL "armeabi-v7a") + set(GSTREAMER_ROOT "${GSTREAMER_ROOT_ANDROID}/armv7") +elseif(ANDROID_ABI STREQUAL "arm64-v8a") + set(GSTREAMER_ROOT "${GSTREAMER_ROOT_ANDROID}/arm64") +elseif(ANDROID_ABI STREQUAL "x86") + set(GSTREAMER_ROOT "${GSTREAMER_ROOT_ANDROID}/x86") +elseif(ANDROID_ABI STREQUAL "x86_64") + set(GSTREAMER_ROOT "${GSTREAMER_ROOT_ANDROID}/x86_64") +else() + message(FATAL_ERROR "Target arch ABI not supported: ${ANDROID_ABI}") +endif() + +list(APPEND CMAKE_MODULE_PATH "${GSTREAMER_ROOT}/share/cmake") + +set(GSTREAMER_NDK_BUILD_PATH "${GSTREAMER_ROOT}/share/gst-android/ndk-build/") +set(GSTREAMER_PLUGINS coreelements) +find_library(LOG_LIB log REQUIRED) +find_package(GStreamerMobile COMPONENTS ${GSTREAMER_PLUGINS} fonts ca_certificates REQUIRED) + +add_library(tutorial-1 SHARED tutorial-1.c dummy.cpp) +target_link_libraries(tutorial-1 + PUBLIC + GStreamer::mobile + ${ANDROID_LIB} + ${LOG_LIB} +) +set_target_properties(tutorial-1 + PROPERTIES + C_VISIBILITY_PRESET hidden + CXX_VISIBILITY_PRESET hidden +) diff --git a/subprojects/gst-docs/examples/tutorials/android/android-tutorial-1/jni/tutorial-1.c b/subprojects/gst-docs/examples/tutorials/android/android-tutorial-1/jni/tutorial-1.c index bc1065911b..d0fc13adf5 100644 --- a/subprojects/gst-docs/examples/tutorials/android/android-tutorial-1/jni/tutorial-1.c +++ b/subprojects/gst-docs/examples/tutorials/android/android-tutorial-1/jni/tutorial-1.c @@ -20,7 +20,7 @@ static JNINativeMethod native_methods[] = { (void *) gst_native_get_gstreamer_info} }; -jint +JNIEXPORT jint JNI_OnLoad (JavaVM * vm, void *reserved) { JNIEnv *env = NULL; diff --git a/subprojects/gst-docs/examples/tutorials/android/android-tutorial-2/.gitignore b/subprojects/gst-docs/examples/tutorials/android/android-tutorial-2/.gitignore index 09614d4230..443f6eb687 100644 --- a/subprojects/gst-docs/examples/tutorials/android/android-tutorial-2/.gitignore +++ b/subprojects/gst-docs/examples/tutorials/android/android-tutorial-2/.gitignore @@ -1,3 +1,4 @@ +.cxx/ .externalNativeBuild/ assets/ gst-android-build/ diff --git a/subprojects/gst-docs/examples/tutorials/android/android-tutorial-2/build.gradle b/subprojects/gst-docs/examples/tutorials/android/android-tutorial-2/build.gradle index 1d1bd567ec..d30a6d4d2e 100644 --- a/subprojects/gst-docs/examples/tutorials/android/android-tutorial-2/build.gradle +++ b/subprojects/gst-docs/examples/tutorials/android/android-tutorial-2/build.gradle @@ -12,7 +12,7 @@ android { externalNativeBuild { - ndkBuild { + cmake { def gstRoot if (project.hasProperty('gstAndroidRoot')) @@ -23,7 +23,7 @@ android { if (gstRoot == null) throw new GradleException('GSTREAMER_ROOT_ANDROID must be set, or "gstAndroidRoot" must be defined in your gradle.properties in the top level directory of the unpacked universal GStreamer Android binaries') - arguments "NDK_APPLICATION_MK=jni/Application.mk", "GSTREAMER_JAVA_SRC_DIR=src", "GSTREAMER_ROOT_ANDROID=$gstRoot", "GSTREAMER_ASSETS_DIR=src/assets" + arguments "-DCMAKE_BUILD_TYPE=Release", "-DANDROID_STL=c++_shared", "-DGSTREAMER_ROOT_ANDROID=$gstRoot" targets "tutorial-2" @@ -52,11 +52,11 @@ android { } externalNativeBuild { - ndkBuild { - path 'jni/Android.mk' + cmake { + path 'jni/CMakeLists.txt' } } - ndkVersion '25.2.9519653' + ndkVersion '25.2.9519653' } afterEvaluate { diff --git a/subprojects/gst-docs/examples/tutorials/android/android-tutorial-2/jni/CMakeLists.txt b/subprojects/gst-docs/examples/tutorials/android/android-tutorial-2/jni/CMakeLists.txt new file mode 100644 index 0000000000..c274d1ff0b --- /dev/null +++ b/subprojects/gst-docs/examples/tutorials/android/android-tutorial-2/jni/CMakeLists.txt @@ -0,0 +1,41 @@ +cmake_minimum_required(VERSION 3.18.1) + +project("android-tutorial-2" LANGUAGES C CXX) + +if(NOT DEFINED GSTREAMER_ROOT_ANDROID) + message(FATAL_ERROR "GSTREAMER_ROOT_ANDROID is not defined!") +endif() + +if(ANDROID_ABI STREQUAL "armeabi") + set(GSTREAMER_ROOT "${GSTREAMER_ROOT_ANDROID}/arm") +elseif(ANDROID_ABI STREQUAL "armeabi-v7a") + set(GSTREAMER_ROOT "${GSTREAMER_ROOT_ANDROID}/armv7") +elseif(ANDROID_ABI STREQUAL "arm64-v8a") + set(GSTREAMER_ROOT "${GSTREAMER_ROOT_ANDROID}/arm64") +elseif(ANDROID_ABI STREQUAL "x86") + set(GSTREAMER_ROOT "${GSTREAMER_ROOT_ANDROID}/x86") +elseif(ANDROID_ABI STREQUAL "x86_64") + set(GSTREAMER_ROOT "${GSTREAMER_ROOT_ANDROID}/x86_64") +else() + message(FATAL_ERROR "Target arch ABI not supported: ${ANDROID_ABI}") +endif() + +list(APPEND CMAKE_MODULE_PATH "${GSTREAMER_ROOT}/share/cmake") + +set(GSTREAMER_NDK_BUILD_PATH "${GSTREAMER_ROOT}/share/gst-android/ndk-build/") +include("${GSTREAMER_NDK_BUILD_PATH}/plugins.cmake") +set(GSTREAMER_PLUGINS ${GSTREAMER_PLUGINS_CORE} ${GSTREAMER_PLUGINS_SYS}) +find_library(LOG_LIB log REQUIRED) +find_package(GStreamerMobile COMPONENTS ${GSTREAMER_PLUGINS} fonts ca_certificates REQUIRED) + +add_library(tutorial-2 SHARED tutorial-2.c dummy.cpp) +target_link_libraries(tutorial-2 + PUBLIC + GStreamer::mobile + ${LOG_LIB} +) +set_target_properties(tutorial-2 + PROPERTIES + C_VISIBILITY_PRESET hidden + CXX_VISIBILITY_PRESET hidden +) diff --git a/subprojects/gst-docs/examples/tutorials/android/android-tutorial-2/jni/tutorial-2.c b/subprojects/gst-docs/examples/tutorials/android/android-tutorial-2/jni/tutorial-2.c index eba72f5f60..c19a2ad59f 100644 --- a/subprojects/gst-docs/examples/tutorials/android/android-tutorial-2/jni/tutorial-2.c +++ b/subprojects/gst-docs/examples/tutorials/android/android-tutorial-2/jni/tutorial-2.c @@ -303,7 +303,7 @@ static JNINativeMethod native_methods[] = { }; /* Library initializer */ -jint +JNIEXPORT jint JNI_OnLoad (JavaVM * vm, void *reserved) { JNIEnv *env = NULL; diff --git a/subprojects/gst-docs/examples/tutorials/android/android-tutorial-3/.gitignore b/subprojects/gst-docs/examples/tutorials/android/android-tutorial-3/.gitignore index 09614d4230..443f6eb687 100644 --- a/subprojects/gst-docs/examples/tutorials/android/android-tutorial-3/.gitignore +++ b/subprojects/gst-docs/examples/tutorials/android/android-tutorial-3/.gitignore @@ -1,3 +1,4 @@ +.cxx/ .externalNativeBuild/ assets/ gst-android-build/ diff --git a/subprojects/gst-docs/examples/tutorials/android/android-tutorial-3/build.gradle b/subprojects/gst-docs/examples/tutorials/android/android-tutorial-3/build.gradle index ed486e5288..8b0c6dd6c3 100644 --- a/subprojects/gst-docs/examples/tutorials/android/android-tutorial-3/build.gradle +++ b/subprojects/gst-docs/examples/tutorials/android/android-tutorial-3/build.gradle @@ -12,7 +12,7 @@ android { externalNativeBuild { - ndkBuild { + cmake { def gstRoot if (project.hasProperty('gstAndroidRoot')) @@ -23,7 +23,7 @@ android { if (gstRoot == null) throw new GradleException('GSTREAMER_ROOT_ANDROID must be set, or "gstAndroidRoot" must be defined in your gradle.properties in the top level directory of the unpacked universal GStreamer Android binaries') - arguments "NDK_APPLICATION_MK=jni/Application.mk", "GSTREAMER_JAVA_SRC_DIR=src", "GSTREAMER_ROOT_ANDROID=$gstRoot", "GSTREAMER_ASSETS_DIR=src/assets" + arguments "-DCMAKE_BUILD_TYPE=Release", "-DANDROID_STL=c++_shared", "-DGSTREAMER_ROOT_ANDROID=$gstRoot" targets "tutorial-3" @@ -52,11 +52,11 @@ android { } externalNativeBuild { - ndkBuild { - path 'jni/Android.mk' + cmake { + path 'jni/CMakeLists.txt' } } - ndkVersion '25.2.9519653' + ndkVersion '25.2.9519653' } afterEvaluate { diff --git a/subprojects/gst-docs/examples/tutorials/android/android-tutorial-3/jni/CMakeLists.txt b/subprojects/gst-docs/examples/tutorials/android/android-tutorial-3/jni/CMakeLists.txt new file mode 100644 index 0000000000..a103a864f2 --- /dev/null +++ b/subprojects/gst-docs/examples/tutorials/android/android-tutorial-3/jni/CMakeLists.txt @@ -0,0 +1,44 @@ +cmake_minimum_required(VERSION 3.18.1) + +project("android-tutorial-3" LANGUAGES C CXX) + +if(NOT DEFINED GSTREAMER_ROOT_ANDROID) + message(FATAL_ERROR "GSTREAMER_ROOT_ANDROID is not defined!") +endif() + +if(ANDROID_ABI STREQUAL "armeabi") + set(GSTREAMER_ROOT "${GSTREAMER_ROOT_ANDROID}/arm") +elseif(ANDROID_ABI STREQUAL "armeabi-v7a") + set(GSTREAMER_ROOT "${GSTREAMER_ROOT_ANDROID}/armv7") +elseif(ANDROID_ABI STREQUAL "arm64-v8a") + set(GSTREAMER_ROOT "${GSTREAMER_ROOT_ANDROID}/arm64") +elseif(ANDROID_ABI STREQUAL "x86") + set(GSTREAMER_ROOT "${GSTREAMER_ROOT_ANDROID}/x86") +elseif(ANDROID_ABI STREQUAL "x86_64") + set(GSTREAMER_ROOT "${GSTREAMER_ROOT_ANDROID}/x86_64") +else() + message(FATAL_ERROR "Target arch ABI not supported: ${ANDROID_ABI}") +endif() + +list(APPEND CMAKE_MODULE_PATH "${GSTREAMER_ROOT}/share/cmake") + +set(GSTREAMER_NDK_BUILD_PATH "${GSTREAMER_ROOT}/share/gst-android/ndk-build/") +include("${GSTREAMER_NDK_BUILD_PATH}/plugins.cmake") +set(GSTREAMER_PLUGINS ${GSTREAMER_PLUGINS_CORE} ${GSTREAMER_PLUGINS_SYS} ${GSTREAMER_PLUGINS_EFFECTS}) +set(GStreamer_EXTRA_DEPS gstreamer-video-1.0 gobject-2.0) +find_library(ANDROID_LIB android REQUIRED) +find_library(LOG_LIB log REQUIRED) +find_package(GStreamerMobile COMPONENTS ${GSTREAMER_PLUGINS} fonts ca_certificates REQUIRED) + +add_library(tutorial-3 SHARED tutorial-3.c dummy.cpp) +target_link_libraries(tutorial-3 + PUBLIC + GStreamer::mobile + ${ANDROID_LIB} + ${LOG_LIB} +) +set_target_properties(tutorial-3 + PROPERTIES + C_VISIBILITY_PRESET hidden + CXX_VISIBILITY_PRESET hidden +) diff --git a/subprojects/gst-docs/examples/tutorials/android/android-tutorial-3/jni/tutorial-3.c b/subprojects/gst-docs/examples/tutorials/android/android-tutorial-3/jni/tutorial-3.c index 6d00b12360..f3e670f51e 100644 --- a/subprojects/gst-docs/examples/tutorials/android/android-tutorial-3/jni/tutorial-3.c +++ b/subprojects/gst-docs/examples/tutorials/android/android-tutorial-3/jni/tutorial-3.c @@ -379,7 +379,7 @@ static JNINativeMethod native_methods[] = { }; /* Library initializer */ -jint +JNIEXPORT jint JNI_OnLoad (JavaVM * vm, void *reserved) { JNIEnv *env = NULL; diff --git a/subprojects/gst-docs/examples/tutorials/android/android-tutorial-4/.gitignore b/subprojects/gst-docs/examples/tutorials/android/android-tutorial-4/.gitignore index 10f3722b17..7e9c31fa11 100644 --- a/subprojects/gst-docs/examples/tutorials/android/android-tutorial-4/.gitignore +++ b/subprojects/gst-docs/examples/tutorials/android/android-tutorial-4/.gitignore @@ -1,3 +1,4 @@ +.cxx/ .externalNativeBuild/ assets/ gst-android-build/ diff --git a/subprojects/gst-docs/examples/tutorials/android/android-tutorial-4/build.gradle b/subprojects/gst-docs/examples/tutorials/android/android-tutorial-4/build.gradle index 31824da07b..d37fb17879 100644 --- a/subprojects/gst-docs/examples/tutorials/android/android-tutorial-4/build.gradle +++ b/subprojects/gst-docs/examples/tutorials/android/android-tutorial-4/build.gradle @@ -12,7 +12,7 @@ android { externalNativeBuild { - ndkBuild { + cmake { def gstRoot if (project.hasProperty('gstAndroidRoot')) @@ -23,7 +23,7 @@ android { if (gstRoot == null) throw new GradleException('GSTREAMER_ROOT_ANDROID must be set, or "gstAndroidRoot" must be defined in your gradle.properties in the top level directory of the unpacked universal GStreamer Android binaries') - arguments "NDK_APPLICATION_MK=jni/Application.mk", "GSTREAMER_JAVA_SRC_DIR=src", "GSTREAMER_ROOT_ANDROID=$gstRoot", "GSTREAMER_ASSETS_DIR=src/assets" + arguments "-DCMAKE_BUILD_TYPE=Release", "-DANDROID_STL=c++_shared", "-DGSTREAMER_ROOT_ANDROID=$gstRoot" targets "tutorial-4" @@ -52,11 +52,11 @@ android { } externalNativeBuild { - ndkBuild { - path 'jni/Android.mk' + cmake { + path 'jni/CMakeLists.txt' } } - ndkVersion '25.2.9519653' + ndkVersion '25.2.9519653' } afterEvaluate { diff --git a/subprojects/gst-docs/examples/tutorials/android/android-tutorial-4/jni/CMakeLists.txt b/subprojects/gst-docs/examples/tutorials/android/android-tutorial-4/jni/CMakeLists.txt new file mode 100644 index 0000000000..7ad05aae6b --- /dev/null +++ b/subprojects/gst-docs/examples/tutorials/android/android-tutorial-4/jni/CMakeLists.txt @@ -0,0 +1,45 @@ +cmake_minimum_required(VERSION 3.18.1) + +project("android-tutorial-4" LANGUAGES C CXX) + +if(NOT DEFINED GSTREAMER_ROOT_ANDROID) + message(FATAL_ERROR "GSTREAMER_ROOT_ANDROID is not defined!") +endif() + +if(ANDROID_ABI STREQUAL "armeabi") + set(GSTREAMER_ROOT "${GSTREAMER_ROOT_ANDROID}/arm") +elseif(ANDROID_ABI STREQUAL "armeabi-v7a") + set(GSTREAMER_ROOT "${GSTREAMER_ROOT_ANDROID}/armv7") +elseif(ANDROID_ABI STREQUAL "arm64-v8a") + set(GSTREAMER_ROOT "${GSTREAMER_ROOT_ANDROID}/arm64") +elseif(ANDROID_ABI STREQUAL "x86") + set(GSTREAMER_ROOT "${GSTREAMER_ROOT_ANDROID}/x86") +elseif(ANDROID_ABI STREQUAL "x86_64") + set(GSTREAMER_ROOT "${GSTREAMER_ROOT_ANDROID}/x86_64") +else() + message(FATAL_ERROR "Target arch ABI not supported: ${ANDROID_ABI}") +endif() + +list(APPEND CMAKE_MODULE_PATH "${GSTREAMER_ROOT}/share/cmake") + +set(GSTREAMER_NDK_BUILD_PATH "${GSTREAMER_ROOT}/share/gst-android/ndk-build/") +include("${GSTREAMER_NDK_BUILD_PATH}/plugins.cmake") +set(GSTREAMER_PLUGINS ${GSTREAMER_PLUGINS_CORE} ${GSTREAMER_PLUGINS_PLAYBACK} ${GSTREAMER_PLUGINS_CODECS} ${GSTREAMER_PLUGINS_NET} ${GSTREAMER_PLUGINS_SYS}) +set(GStreamer_EXTRA_DEPS gstreamer-video-1.0) +set(G_IO_MODULES openssl) +find_library(ANDROID_LIB android REQUIRED) +find_library(LOG_LIB log REQUIRED) +find_package(GStreamerMobile COMPONENTS ${GSTREAMER_PLUGINS} fonts ca_certificates REQUIRED) + +add_library(tutorial-4 SHARED tutorial-4.c dummy.cpp) +target_link_libraries(tutorial-4 + PUBLIC + GStreamer::mobile + ${ANDROID_LIB} + ${LOG_LIB} +) +set_target_properties(tutorial-4 + PROPERTIES + C_VISIBILITY_PRESET hidden + CXX_VISIBILITY_PRESET hidden +) diff --git a/subprojects/gst-docs/examples/tutorials/android/android-tutorial-4/jni/tutorial-4.c b/subprojects/gst-docs/examples/tutorials/android/android-tutorial-4/jni/tutorial-4.c index 525bfb8cd9..3c02696faf 100644 --- a/subprojects/gst-docs/examples/tutorials/android/android-tutorial-4/jni/tutorial-4.c +++ b/subprojects/gst-docs/examples/tutorials/android/android-tutorial-4/jni/tutorial-4.c @@ -650,7 +650,7 @@ static JNINativeMethod native_methods[] = { }; /* Library initializer */ -jint +JNIEXPORT jint JNI_OnLoad (JavaVM * vm, void *reserved) { JNIEnv *env = NULL; diff --git a/subprojects/gst-docs/examples/tutorials/android/android-tutorial-5/.gitignore b/subprojects/gst-docs/examples/tutorials/android/android-tutorial-5/.gitignore index 10f3722b17..7e9c31fa11 100644 --- a/subprojects/gst-docs/examples/tutorials/android/android-tutorial-5/.gitignore +++ b/subprojects/gst-docs/examples/tutorials/android/android-tutorial-5/.gitignore @@ -1,3 +1,4 @@ +.cxx/ .externalNativeBuild/ assets/ gst-android-build/ diff --git a/subprojects/gst-docs/examples/tutorials/android/android-tutorial-5/build.gradle b/subprojects/gst-docs/examples/tutorials/android/android-tutorial-5/build.gradle index fd44f5836e..01ed08d83a 100644 --- a/subprojects/gst-docs/examples/tutorials/android/android-tutorial-5/build.gradle +++ b/subprojects/gst-docs/examples/tutorials/android/android-tutorial-5/build.gradle @@ -12,7 +12,7 @@ android { externalNativeBuild { - ndkBuild { + cmake { def gstRoot if (project.hasProperty('gstAndroidRoot')) @@ -23,7 +23,7 @@ android { if (gstRoot == null) throw new GradleException('GSTREAMER_ROOT_ANDROID must be set, or "gstAndroidRoot" must be defined in your gradle.properties in the top level directory of the unpacked universal GStreamer Android binaries') - arguments "NDK_APPLICATION_MK=jni/Application.mk", "GSTREAMER_JAVA_SRC_DIR=src", "GSTREAMER_ROOT_ANDROID=$gstRoot", "GSTREAMER_ASSETS_DIR=src/assets" + arguments "-DCMAKE_BUILD_TYPE=Release", "-DANDROID_STL=c++_shared", "-DGSTREAMER_ROOT_ANDROID=$gstRoot" targets "tutorial-5" @@ -52,11 +52,11 @@ android { } externalNativeBuild { - ndkBuild { - path 'jni/Android.mk' + cmake { + path 'jni/CMakeLists.txt' } } - ndkVersion '25.2.9519653' + ndkVersion '25.2.9519653' } afterEvaluate { diff --git a/subprojects/gst-docs/examples/tutorials/android/android-tutorial-5/jni/CMakeLists.txt b/subprojects/gst-docs/examples/tutorials/android/android-tutorial-5/jni/CMakeLists.txt new file mode 100644 index 0000000000..c4aeb5c5db --- /dev/null +++ b/subprojects/gst-docs/examples/tutorials/android/android-tutorial-5/jni/CMakeLists.txt @@ -0,0 +1,45 @@ +cmake_minimum_required(VERSION 3.18.1) + +project("android-tutorial-5" LANGUAGES C CXX) + +if(NOT DEFINED GSTREAMER_ROOT_ANDROID) + message(FATAL_ERROR "GSTREAMER_ROOT_ANDROID is not defined!") +endif() + +if(ANDROID_ABI STREQUAL "armeabi") + set(GSTREAMER_ROOT "${GSTREAMER_ROOT_ANDROID}/arm") +elseif(ANDROID_ABI STREQUAL "armeabi-v7a") + set(GSTREAMER_ROOT "${GSTREAMER_ROOT_ANDROID}/armv7") +elseif(ANDROID_ABI STREQUAL "arm64-v8a") + set(GSTREAMER_ROOT "${GSTREAMER_ROOT_ANDROID}/arm64") +elseif(ANDROID_ABI STREQUAL "x86") + set(GSTREAMER_ROOT "${GSTREAMER_ROOT_ANDROID}/x86") +elseif(ANDROID_ABI STREQUAL "x86_64") + set(GSTREAMER_ROOT "${GSTREAMER_ROOT_ANDROID}/x86_64") +else() + message(FATAL_ERROR "Target arch ABI not supported: ${ANDROID_ABI}") +endif() + +list(APPEND CMAKE_MODULE_PATH "${GSTREAMER_ROOT}/share/cmake") + +set(GSTREAMER_NDK_BUILD_PATH "${GSTREAMER_ROOT}/share/gst-android/ndk-build/") +include("${GSTREAMER_NDK_BUILD_PATH}/plugins.cmake") +set(GSTREAMER_PLUGINS ${GSTREAMER_PLUGINS_CORE} ${GSTREAMER_PLUGINS_PLAYBACK} ${GSTREAMER_PLUGINS_CODECS} ${GSTREAMER_PLUGINS_NET} ${GSTREAMER_PLUGINS_SYS}) +set(GStreamer_EXTRA_DEPS gstreamer-video-1.0) +set(G_IO_MODULES openssl) +find_library(ANDROID_LIB android REQUIRED) +find_library(LOG_LIB log REQUIRED) +find_package(GStreamerMobile COMPONENTS ${GSTREAMER_PLUGINS} fonts ca_certificates REQUIRED) + +add_library(tutorial-5 SHARED tutorial-5.c dummy.cpp) +target_link_libraries(tutorial-5 + PUBLIC + GStreamer::mobile + ${ANDROID_LIB} + ${LOG_LIB} +) +set_target_properties(tutorial-5 + PROPERTIES + C_VISIBILITY_PRESET hidden + CXX_VISIBILITY_PRESET hidden +) diff --git a/subprojects/gst-docs/examples/tutorials/android/android-tutorial-5/jni/tutorial-5.c b/subprojects/gst-docs/examples/tutorials/android/android-tutorial-5/jni/tutorial-5.c index 2a2a7ec7b9..0ecfb7c66c 100755 --- a/subprojects/gst-docs/examples/tutorials/android/android-tutorial-5/jni/tutorial-5.c +++ b/subprojects/gst-docs/examples/tutorials/android/android-tutorial-5/jni/tutorial-5.c @@ -660,7 +660,7 @@ static JNINativeMethod native_methods[] = { }; /* Library initializer */ -jint +JNIEXPORT jint JNI_OnLoad (JavaVM * vm, void *reserved) { JNIEnv *env = NULL;