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

17,366

Solution 1

  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.

Solution 2

Just move your project to path without spaces

Example to /Users/myuser/Documents/android-project-folder

It helped me

Share:
17,366

Related videos on Youtube

unmanned15
Author by

unmanned15

Updated on June 04, 2022

Comments

  • unmanned15
    unmanned15 almost 2 years

    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
    
    • Alex Cohn
      Alex Cohn over 4 years
      This ndkBuild_build_command.txt file does not belong to your computer, it comes from some Linux machine. Please delete both .cxx and .externalNdkBuild directories, and run Gradle Sync again. You will get another ndkBuild_build_command.txt file. Please post it here, or use the same parameters as stated in this file, to run ndk-build.cmd from CMD prompt. I hope it will give you good hints to what went wrong.
  • unmanned15
    unmanned15 over 4 years
    I added the "V=1" to the ndkBuild. I added to the post the errors that I received.
  • unmanned15
    unmanned15 over 4 years
    Thanks, moved the arguments to the appropriate section. Unfortunately still receive the original error again. I also added the errors from the run build section if that could help
  • Alex Cohn
    Alex Cohn over 4 years
    Before the errors, does there appear some other output in the build log? At any rate, look into the C:\Users\m0l\Downloads\gstreamer-tutorial5-master\app directory. There is a .cxx or .externalNativeBuild subdirectory. Inside, there should be some text files that show how your ndk-build is being invoked.
  • unmanned15
    unmanned15 over 4 years
    @AlexCohn I do have the .cxx and .externalNativeBuild folders. In the .cxx folder there is ndk_locator_record.json and ndkBuild folder which contains build_model.json & json_generation_record.json. The .externalNativeBuild folder contains ndkBuild\debug which contains all of the ABI (arm64-v8a etc). Within each one of the ABI folders there is android_gradle_build.json, ndkBuild_build_command.txt, ndkBuild_build_output.txt I added files above that looked interesting. Seems like the executable line has a different path. I'm not sure what to look for.
  • PunK _l_ RuLz
    PunK _l_ RuLz over 4 years
    Thank you so much for this. It has helped me a lot.
  • Damien Doumer
    Damien Doumer about 4 years
    Thank you, But when I follow these steps, it builds but at some point I get an error stating "Native build error" I guess it is linke to the make file. This error is weired cause it does not state the cause of the error.
  • Wale
    Wale over 3 years
    How does this solve the problem ? it basically only might allow your gradle build without any error but it won't make the native library available.