How to import GStreamer into Android source code?

Hi,

Do you know how to import GStreamer into Android source code and configure Android. mk?

Best Regards,
Nancy

have you tried this?

https://gstreamer.freedesktop.org/documentation/tutorials/android/index.html?gi-language=c

Yes. I can use GStreamer on Android Studio successfully.
When I want to import GStreamer to Android source code, I cannot configure it correctly .

Android.mk under jni like this:

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

ifndef GSTREAMER_ROOT_ANDROID
GSTREAMER_ROOT_ANDROID := $(LOCAL_PATH)/gstreamer-1.0-android-universal-1.22.6
endif
GSTREAMER_ROOT := $(GSTREAMER_ROOT_ANDROID)/arm64

GSTREAMER_NDK_BUILD_PATH := $(GSTREAMER_ROOT)/share/gst-android/ndk-build

include $(GSTREAMER_NDK_BUILD_PATH)/plugins.mk

GSTREAMER_PLUGINS := $(GSTREAMER_PLUGINS_CORE)
$(GSTREAMER_PLUGINS_PLAYBACK)
$(GSTREAMER_PLUGINS_CODECS)
$(GSTREAMER_PLUGINS_NET)
$(GSTREAMER_PLUGINS_SYS)
$(GSTREAMER_PLUGINS_CODECS_RESTRICTED)
opengl
G_IO_MODULES := openssl
GSTREAMER_EXTRA_DEPS := gstreamer-video-1.0 gstreamer-rtsp-server-1.0 gobject-2.0
GSTREAMER_EXTRA_LIBS := -liconv -lgstbase-1.0 -lGLESv2 -lEGL
include $(GSTREAMER_NDK_BUILD_PATH)/gstreamer-1.0.mk

include $(CLEAR_VARS)

LOCAL_MODULE := libandroid_camera
LOCAL_SRC_FILES := android_camera.c
LOCAL_SHARED_LIBRARIES := libgstreamer_android
LOCAL_LDLIBS := -landroid -llog -lcamera2ndk -lmediandk
include $(BUILD_SHARED_LIBRARY)

===============================================================

error like this :
“libandroid_camera (SHARED_LIBRARIES android-arm64) missing libgstreamer_android (SHARED_LIBRARIES android-arm64)”

Here is my, very old version. But it still works. Maybe some parts are not needed anymore

LOCAL_PATH := $(call my-dir)


include $(CLEAR_VARS)
LOCAL_MODULE:= libcrypto
LOCAL_SRC_FILES:= $(LOCAL_PATH)/openssl-lib/$(TARGET_ARCH_ABI)/libcrypto.a
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/openssl-lib/$(TARGET_ARCH_ABI)/include/
include $(PREBUILT_STATIC_LIBRARY)


include $(CLEAR_VARS)
LOCAL_MODULE    := gstreamerExtra
LOCAL_SRC_FILES :=      $(LOCAL_PATH)/GStreamerExtra/gstreamerExtra.cpp \
                        $(LOCAL_PATH)/GStreamerExtra/gstreamerExtraData.cpp \
                        ...          
LOCAL_SHARED_LIBRARIES := gstreamer_android libcrypto
LOCAL_LDLIBS := -llog
LOCAL_CPP_FEATURES := exceptions
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/GStreamerExtra
include $(BUILD_SHARED_LIBRARY)

include $(CLEAR_VARS)
LOCAL_MODULE    := gstreamerJni
LOCAL_SRC_FILES := $(LOCAL_PATH)/gstreamerJni.cpp
LOCAL_SHARED_LIBRARIES := gstreamer_android gstreamerExtra
LOCAL_LDLIBS := -llog
LOCAL_CPP_FEATURES := exceptions
include $(BUILD_SHARED_LIBRARY)

include $(CLEAR_VARS)
ifndef GSTREAMER_ROOT_ANDROID
$(error GSTREAMER_ROOT_ANDROID is not defined!)
endif

ifeq ($(TARGET_ARCH_ABI),armeabi)
GSTREAMER_ROOT        := $(GSTREAMER_ROOT_ANDROID)/arm
else ifeq ($(TARGET_ARCH_ABI),armeabi-v7a)
GSTREAMER_ROOT        := $(GSTREAMER_ROOT_ANDROID)/armv7
else ifeq ($(TARGET_ARCH_ABI),arm64-v8a)
GSTREAMER_ROOT        := $(GSTREAMER_ROOT_ANDROID)/arm64
else ifeq ($(TARGET_ARCH_ABI),x86)
GSTREAMER_ROOT        := $(GSTREAMER_ROOT_ANDROID)/x86
else ifeq ($(TARGET_ARCH_ABI),x86_64)
GSTREAMER_ROOT        := $(GSTREAMER_ROOT_ANDROID)/x86_64
else
$(error Target arch ABI not supported: $(TARGET_ARCH_ABI))
endif

GSTREAMER_NDK_BUILD_PATH  := $(GSTREAMER_ROOT)/share/gst-android/ndk-build
include $(GSTREAMER_NDK_BUILD_PATH)/plugins.mk
G_IO_MODULES              := openssl
GSTREAMER_PLUGINS         := $(GSTREAMER_PLUGINS_CODECS_RESTRICTED) $(GSTREAMER_PLUGINS_SYS) $(GSTREAMER_PLUGINS_EFFECTS) $(GSTREAMER_PLUGINS_NET) $(GSTREAMER_PLUGINS_CODECS) $(GSTREAMER_PLUGINS_CORE)
GSTREAMER_EXTRA_DEPS      := gstreamer-video-1.0
include $(GSTREAMER_NDK_BUILD_PATH)/gstreamer-1.0.mk

Thank you for your help.

Can you tell me that the content of the last line in gstreamer_prebuilt.mk?
Default is “include $(BUILD_SYSTEM)/build-module.mk",
but build fail and error is :
error: build/make/core/build-module.mk: No such file or directory

So I still cannot compile in the source code.

What exactly are you trying to do here? You say that this works in android studio. Are you running gradle directly? Or maybe even ndk-build directly? What environment are you attempting to run ndk-build in? Are you attempting to build as part of another project? AOSP perhaps?

I want to import my apk (which uses GStreamer and works well in Android studio) into the Android project (AOSP).

I see. You will need to rewrite GStreamer’s ndk-build integration for the specific environment provided by the AOSP build process. The default GStreamer ndk-build integration is not designed for that.

Okay, I got it.
Thank you.

i have a problem of sample return null how ever the stream is running as rtsp tcp. i dont know where i am wrong like if i am using corrupt libraries or my code is the problem.

i am new to android gstreamer development.