android-studioandroid-ndkgstreamerndk-build

Android Studio ERROR: Executing external native build for ndkBuild when trying to run Gstreamer tutorial


I am trying to run the gstreamer android tutorial-5 in Android Sudio 3.5 (https://gitlab.freedesktop.org/gstreamer/gst-docs/tree/master/examples/tutorials/android)(https://gitlab.com/eduardoprado/gstreamer-tutorial5) but get the following error:

ERROR: Cause: executing external native build for ndkBuild C:\Users\Downloads\gst_docs_master_examples_tutorials_android\examples\tutorials\android\android-tutorial-1\jni\Android.mk. 

I have been following both the gstreamer android tutorials on the gstreamer website along with the stackoverflow thread Gstreamer examples in Android Studio.

The first goal is to get the gstreamer running on android studio.

There are some threads that error is related to white spaces in the path directory but I have checked and all folders have no white space. Below are some of the files that I have been working with and adapting to make the tutorial run.

I have also set my windows environment variable GSTREAMER_ROOT_ANDROID to the unpacked gstreamer binaries along with set it in the android.mk file.

local.properties file

## This file must *NOT* be checked into Version Control Systems,
# as it contains information specific to your local configuration.
#
# Location of the SDK. This is only used by Gradle.
# For customization when using a Version Control System, please read the
# header note.
#Mon Sep 09 08:16:12 EDT 2019
sdk.dir=C\:\\Users\\AppData\\Local\\Android\\Sdk
ndk.dir=C\:\\Users\\AppData\\Local\\Android\\Sdk\\ndk\\20.0.5594570

Android.mk

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE    := tutorial-5
LOCAL_SRC_FILES := tutorial-5.c
LOCAL_SHARED_LIBRARIES := gstreamer_android
LOCAL_LDLIBS := -llog -landroid
include $(BUILD_SHARED_LIBRARY)

GSTREAMER_ROOT_ANDROID := C\:\\gstreamer_android_binaries

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
GSTREAMER_PLUGINS         := $(GSTREAMER_PLUGINS_CORE) $(GSTREAMER_PLUGINS_PLAYBACK) $(GSTREAMER_PLUGINS_CODECS) $(GSTREAMER_PLUGINS_NET) $(GSTREAMER_PLUGINS_SYS)
G_IO_MODULES              := gnutls
GSTREAMER_EXTRA_DEPS      := gstreamer-video-1.0
include $(GSTREAMER_NDK_BUILD_PATH)/gstreamer-1.0.mk

build.gradle (app)

apply plugin: 'com.android.application'

android {
    compileSdkVersion 29
    buildToolsVersion "26.0.3"

    defaultConfig {
        applicationId "com.gst_sdk_tutorials.tutorial_5"
        minSdkVersion 14
        targetSdkVersion 29

        externalNativeBuild {
            ndkBuild {
                arguments "V=1"
            }
        }

        ndk {
            moduleName "tutorial-5"
            abiFilters 'x86', 'armeabi-v7a', 'arm64-v8a'
        }
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }
    externalNativeBuild {
        ndkBuild {
            path 'src/main/jni/Android.mk'
        }
    }
}

build.gradle (project)

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    repositories {
        jcenter()
        google()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.5.0'
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

gradle-wrapper.properties

#Mon Sep 09 14:10:17 EDT 2019
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip

UPDATE Added the argument "V=1" to the ndkBuild section and received the same error:

ERROR: Cause: executing external native build for ndkBuild C:\Users\Downloads\gstreamer-tutorial5-master\app\src\main\jni\Android.mk

Solution

    1. Download the entire gstreamer android studio tutorial directory (https://gitlab.freedesktop.org/gstreamer/gst-docs/)

    2)Open Android Studio -> Open an existing Android Studio Project

    1. Open the entire android tutorial directory examples/tutorials/android as a project

    4)Once the project is open change the view on the left side of the screen to Project

    1. Right click near local.properties file -> New -> File

    2. Create a new file called gradle.properties

    3. In the new gradle.properties file copy and paste the below code.

    # gstAndroidRoot can be set to point to the unpacked GStreamer android top-level directory
    # containing each architecture in subdirectories, or else set the GSTREAMER_ROOT_ANDROID
    # environment variable to that location
    gstAndroidRoot=/gstreamer_android_binaries
    

    NOTE Change the gstAndroidRoot variable to your file path where you downloaded the gstreamer binaries and unzipped them. Gstreamer can be downloaded from here for Android (https://gstreamer.freedesktop.org/data/pkg/android/)

    1. Now we need to set up NDK directory. Make sure you download and have NDK enabled under SDK tools.

    9)This will download the latest NDK version. However gstreamer currently will not build with the latest NDK. We need to download NDK Revision 18b (https://developer.android.com/ndk/downloads/older_releases) If you do not use NDK version 18 you will likely get an error Android NDK: Assertion failure: SYSROOT_LINK is not defined . Stop. Open File

    1. Unzip the downloaded NDK 18b directory.

    2. Take the unzipped android-ndk-r18b directory and move it to where the ndk folder is under AppData\Local\Android\Sdk\ndk

    3. You should now have two folders within Android\Sdk\ndk. 20.0.5594570 (or latest version) and android-ndk-r18b

    4. In android studio go to File -> project Structure

    5. Under Android NDK location point to the NDK 18 directory. Example: C:\Users\AppData\Local\Android\Sdk\ndk\android-ndk-r18b

    6. Connect a phone with USB debugging and run!

    7. If you get an error on the phone stating it is for an older version of android. Go back to Android Studio and switch to Android View on the left side of the screen. Under Gradle Scripts select the build.gradle for the appropriate tutorial. Change the compileSdkVersion 29, minSDKVersion 15, and targetSDKVersion 29.