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: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/7794>
This commit is contained in:
L. E. Segovia 2024-05-02 00:15:10 +00:00 committed by GStreamer Marge Bot
parent 410e77be6c
commit 126a9cec06
20 changed files with 250 additions and 29 deletions

View file

@ -1,3 +1,4 @@
.cxx/
.externalNativeBuild/
assets/
gst-android-build/

View file

@ -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'

View file

@ -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
)

View file

@ -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;

View file

@ -1,3 +1,4 @@
.cxx/
.externalNativeBuild/
assets/
gst-android-build/

View file

@ -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 {

View file

@ -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
)

View file

@ -303,7 +303,7 @@ static JNINativeMethod native_methods[] = {
};
/* Library initializer */
jint
JNIEXPORT jint
JNI_OnLoad (JavaVM * vm, void *reserved)
{
JNIEnv *env = NULL;

View file

@ -1,3 +1,4 @@
.cxx/
.externalNativeBuild/
assets/
gst-android-build/

View file

@ -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 {

View file

@ -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
)

View file

@ -379,7 +379,7 @@ static JNINativeMethod native_methods[] = {
};
/* Library initializer */
jint
JNIEXPORT jint
JNI_OnLoad (JavaVM * vm, void *reserved)
{
JNIEnv *env = NULL;

View file

@ -1,3 +1,4 @@
.cxx/
.externalNativeBuild/
assets/
gst-android-build/

View file

@ -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 {

View file

@ -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
)

View file

@ -650,7 +650,7 @@ static JNINativeMethod native_methods[] = {
};
/* Library initializer */
jint
JNIEXPORT jint
JNI_OnLoad (JavaVM * vm, void *reserved)
{
JNIEnv *env = NULL;

View file

@ -1,3 +1,4 @@
.cxx/
.externalNativeBuild/
assets/
gst-android-build/

View file

@ -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 {

View file

@ -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
)

View file

@ -660,7 +660,7 @@ static JNINativeMethod native_methods[] = {
};
/* Library initializer */
jint
JNIEXPORT jint
JNI_OnLoad (JavaVM * vm, void *reserved)
{
JNIEnv *env = NULL;