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

6

12

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
Fiddler answered 9/9, 2019 at 13:51 Comment(3)
Is there no actual error anywhere? There's no error message that I see here other than "something went wrong".Unsavory
Under Run Build -> Gradle Sync Issues there is an 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.Fiddler
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.Media
O
4
  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.

Overthrow answered 2/10, 2019 at 18:15 Comment(2)
Thank you so much for this. It has helped me a lot.Micco
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.Scutate
L
8

Just move your project to path without spaces

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

It helped me

Larina answered 5/7, 2021 at 9:45 Comment(0)
O
4
  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.

Overthrow answered 2/10, 2019 at 18:15 Comment(2)
Thank you so much for this. It has helped me a lot.Micco
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.Scutate
M
0

It could easily be that the paths you are using are simply too long for Windows command line. To understand better what is going on, add "V=1" to the list of arguments for ndkBuild, and you will see all build commands as they are executed in your build console.

Media answered 9/9, 2019 at 17:44 Comment(1)
I added the "V=1" to the ndkBuild. I added to the post the errors that I received.Fiddler
U
0

The arguments configurations belongs in the android.defaultConfig.externalNativeBuild.ndkBuild section, not android.externalNativeBuild.ndkBuild. See the docs: https://developer.android.com/ndk/guides/cmake#variables

Unsavory answered 9/9, 2019 at 20:22 Comment(3)
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 helpFiddler
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.Media
@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.Fiddler
T
0

Just copy the path of Android.mk and place it like

externalNativeBuild {
        ndkBuild {
            path 'sourcecode_destination\app\src\main\jni\Android.mk'
        }
    }

    ndkVersion '22.0.7026061'
} 
Tamera answered 18/1, 2022 at 6:17 Comment(0)
O
-1

Please, just comment this from build.gradle (app):

externalNativeBuild {
         ndkBuild {
             path 'src/main/jni/Android.mk'
         }
     }
Orson answered 29/5, 2020 at 12:10 Comment(1)
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.Brutalize

© 2022 - 2024 — McMap. All rights reserved.