Unable to build gstreamer using Android NDK

2.7k views Asked by At

I'm following this tutorial to build a gstreamer project - http://docs.gstreamer.com/display/GstSDK/Android+tutorial+1%3A+Link+against+GStreamer

I have created two files named main.cpp and Android.mk inside jni folder. jni folder is inside the Android project. Though, I don't think it's location matters anyways. these are the contents of these two files - Android.mk -

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE    := test
LOCAL_SRC_FILES := main.c
LOCAL_SHARED_LIBRARIES := gstreamer_android
LOCAL_LDLIBS := -llog
include $(BUILD_SHARED_LIBRARY)

ifndef GSTREAMER_SDK_ROOT
ifndef GSTREAMER_SDK_ROOT_ANDROID
$(error GSTREAMER_SDK_ROOT_ANDROID is not defined!)
endif
GSTREAMER_SDK_ROOT        := $(GSTREAMER_SDK_ROOT_ANDROID)
endif
GSTREAMER_NDK_BUILD_PATH  := $(GSTREAMER_SDK_ROOT)/share/gst-android/ndk-build/
GSTREAMER_PLUGINS         := coreelements
include $(GSTREAMER_NDK_BUILD_PATH)/gstreamer.mk

main.cpp -

#include <string.h>
#include <jni.h>
#include <android/log.h>
#include <gst/gst.h>

jstring gst_native_get_gstreamer_info (JNIEnv* env, jobject thiz) {
    char *version_utf8 = gst_version_string();
    jstring *version_jstring = (*env)->NewStringUTF(env, version_utf8);
    g_free (version_utf8);
    return version_jstring;
}

static JNINativeMethod native_methods[] = {
{ "nativeGetGStreamerInfo", "()Ljava/lang/String;", (void *)     gst_native_get_gstreamer_info}
};

jint JNI_OnLoad(JavaVM *vm, void *reserved) {
    JNIEnv *env = NULL;
    if ((*vm)->GetEnv(vm, (void**) &env, JNI_VERSION_1_4) != JNI_OK) {
        __android_log_print (ANDROID_LOG_ERROR, "tutorial-1", "Could not retrieve JNIEnv");
        return 0;
    }
    jclass klass = (*env)->FindClass (env, "com/gst_sdk_tutorials/tutorial_1/Tutorial1");
    (*env)->RegisterNatives (env, klass, native_methods, G_N_ELEMENTS(native_methods));
    return JNI_VERSION_1_4;
}

When I execute ndk-build from this directory, I get the following error -

make: -n: Command not found
/bin/sh: 0: Illegal option - 
/bin/sh: 0: Illegal option - 
/bin/sh: 0: Illegal option - 
/bin/sh: 0: Illegal option - 
 /bin/sh: 0: Illegal option - 
/bin/sh: 0: Illegal option - 
/bin/sh: 0: Illegal option - 
/bin/sh: 0: Illegal option - 
/bin/sh: 0: Illegal option - 
GStreamer      : [GEN] => gst-build/gstreamer_android.c
/bin/sh: 1: i: not found
make: [genstatic] Error 127 (ignored)
/bin/sh: 1: i: not found
make: [genstatic] Error 127 (ignored)
/bin/sh: 1: i: not found
make: [genstatic] Error 127 (ignored)
/bin/sh: 1: i: not found
make: [genstatic] Error 127 (ignored)
GStreamer      : [COMPILE] => gst-build/gstreamer_android.c
gst-build/gstreamer_android.c:9:2: error: stray '@' in program
  @PLUGINS_DECLARATION@
  ^
gst-build/gstreamer_android.c:9:22: error: stray '@' in program
  @PLUGINS_DECLARATION@
                      ^
gst-build/gstreamer_android.c:12:2: error: stray '@' in program
   @G_IO_MODULES_DECLARE@
  ^
gst-build/gstreamer_android.c:9:3: error: unknown type name 'PLUGINS_DECLARATION'
  @PLUGINS_DECLARATION@
   ^
gst-build/gstreamer_android.c:12:23: error: stray '@' in program
  @G_IO_MODULES_DECLARE@
                       ^
gst-build/gstreamer_android.c:15:1: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'void'

And it goes...

2

There are 2 answers

0
omerjerk On

I solved the error by editing the file - gstreamer-sdk-android-arm-debug-2013.6/share/gst-android/ndk-build/gstreamer.mk. In the file, the variable HOST_SED is not defined in case of linux. I had to set it to the linux command line tool sed and it worked. It's really bad that such a big project has such silly errors in their scripts. Also, I had to downgrade my NDK to ndk-r9.

0
Brian D On

The latest versions of GStreamer for Android are compatible with ndk-r10e (at least they address the HOST_SED issue). See this bug for reference: https://bugzilla.gnome.org/show_bug.cgi?id=750162

Here you can find the latest pre-built GStreamer for Android package: http://gstreamer.freedesktop.org/data/pkg/android/1.5.91/

The version that you're linking against, from the tutorial, is really old.

Edit: I can confirm that this works now :)

enter image description here