Hello, the title says it all.
What i've done so far:
1. I installed gstreamer on my linux pc.
https://gstreamer.freedesktop.org/documentation/installing/on-linux.html?gi-language=c
2. I read the very informativ tutorials at:
https://gstreamer.freedesktop.org/documentation/tutorials/?gi-language=c
3. I tried and played around with the qmlsink module:
https://gitlab.freedesktop.org/gstreamer/gstreamer/-/tree/main/subprojects/gst-plugins-good/tests/examples/qt/qmlsink?ref_type=heads
4. I downloaded the precompiled gstreamer libraries for android:
https://gstreamer.freedesktop.org/data/pkg/android/
5. I followed the install guide for gstreamer on android:
https://gstreamer.freedesktop.org/documentation/installing/for-android-development.html?gi-language=c
I already had NDK, gradle and co, because i already develop cross-platform with Qt.
6. I built the android tutorials with gradle:
https://gitlab.freedesktop.org/gstreamer/gstreamer/-/tree/main/subprojects/gst-docs/examples/tutorials/android?ref_type=heads
7. So, now, the time has come to combine these things.
I adapted the qmake based project from the qmlsink example.
My test project contains a simple pipeline ("audiotestsrc ! autoaudiosink"), which works just fine on linux.
So i naively set in the pro file:
PKGCONFIG=/PATH/TO/GSTREAMER/arm64/lib/gstreamer-1.0/pkgconfig in the pro file.
And i got: "Cross compiling without sysroot. Disabling pkg-config."
So, i tried to add the libraries manually, which seemed to work instantly.
It compiled, it ran, it crashed...
It crashed not at the beginning, it crashed at a very boring line in the middle.
I tried a lot of combinations of:
CMake QMake
Qt 6.5 6.8 6.11
GStreamer 1.26.13 1.28.3 1.29.1
Debian 12 (openjdk 17), Debian 13 (openjdk 21)
Huawai Android 7 (API 24), Samsung Android 16 (API 36)
And the result is always the same, it crashes at the same line.
Whether its my old Huawei with Qt 6.5, or with the new Samsung and Qt 6.11.
So, this issue can't be new...
I searched the forum and the web. The conclusion: other people added the libraries manually and it worked (a few year ago).
Most of the information is not up-to-date, library names and the need to register modules for example.
This seemed to be a dead end, so...
8. I looked closer into the code of the working Android+GStreamer tutorial programs.
https://gitlab.freedesktop.org/gstreamer/gstreamer/-/tree/main/subprojects/gst-docs/examples/tutorials/android/android-tutorial-1?ref_type=heads
Starting with the build.gradle file of tutorial-1.
This pointed me to the file 'jni/CMakeLists.txt' within the project.
I tried to copy paste the relevant parts into the cmake file of my test project.
cmake_minimum_required(VERSION 3.16)
project(TestProject_GStreamer_CMake VERSION 0.1 LANGUAGES CXX)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package(Qt6 REQUIRED COMPONENTS Quick)
qt_standard_project_setup(REQUIRES 6.8)
qt_add_executable(appTestProject_GStreamer_CMake
main.cpp
gst_handler.h
gst_handler.cpp
)
qt_add_qml_module(appTestProject_GStreamer_CMake
URI TestProject_GStreamer_CMake
QML_FILES
Main.qml
)
# Qt for iOS sets MACOSX_BUNDLE_GUI_IDENTIFIER automatically since Qt 6.1.
# If you are developing for iOS or macOS you should consider setting an
# explicit, fixed bundle identifier manually though.
set_target_properties(appTestProject_GStreamer_CMake PROPERTIES
# MACOSX_BUNDLE_GUI_IDENTIFIER com.example.appTestProject_GStreamer_CMake
MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
MACOSX_BUNDLE TRUE
WIN32_EXECUTABLE TRUE
)
#
#
#
# LINUX - working fine
#
#
#
if(LINUX)
find_package(PkgConfig REQUIRED)
pkg_search_module(gstreamer REQUIRED IMPORTED_TARGET gstreamer-1.0)
target_link_libraries(appTestProject_GStreamer_CMake
PRIVATE
Qt6::Quick
PkgConfig::gstreamer
)
endif()
#
#
#
# ANDROID - not working
#
#
#
if(ANDROID)
set(GSTREAMER_ROOT_ANDROID "/home/felsi/Dokumente/TestProjects/gstreamer-1.0-android-universal-1.26.11")
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 REQUIRED)
target_link_libraries(appTestProject_GStreamer_CMake
PRIVATE Qt6::Quick
PUBLIC
GStreamer::mobile
${ANDROID_LIB}
${LOG_LIB}
)
endif()
install(TARGETS appTestProject_GStreamer_CMake
BUNDLE DESTINATION .
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
And i got "Could NOT find GLIB2", triggered at find_package(). The glib library is one of the precompiled libraries, included in the downloaded folder. It turned out, that find_package() calls a cmake file, which was added with list(APPEND CMAKE_MODULE_PATH ...).
So i followed the rabbit to ".../share/cmake/FindGSTreamer.cmake" within the downloaded folder of the precompiled gstreamer libraries. This cmake file uses pkg-config and prepares the package, so that the cmake file in the project can easily find and link the needed modules. But i have no clue, why it's working for the tutorial, but not for my test project. I lack knowledge.
However, this approach does not seem to be a dead end, it could be even quite elegant compared to the old qmake solutions, spread across the web. Unfortunately, i ran out of ideas how to fix it, because i am not very experienced with cmake and androiddeployqt. But maybe with a little help from some awesome person, who is, this might work...
Thank you for reading the whole post.