Upgrading GStreamer. Expected NDK STL shared object file

857 Views Asked by At

I have been trying to upgrade GStreamer to version 1.16 from 1.14 in my android application but have encountered some problems. Version 1.16 requires, according to gstreamer's website, Android NDK r18b. When I try to run GStreamer 1.16 with NDK r18b I get an error in android studio:

Expected ndk stl shared object file at /home/exjobb/Documents/android-ndk-r18-b-linux-x86_64/android-ndk-r18b/sources/cxx-stl/gnu-libstdc++/4.9/libs/armeabi-v7a /libgnustl_shared.so

The cxx-stl folder is not on my computer, nor are the folders / files that come after.

I have googled and it seems that a general recommendation is to downgrade to r17c. I can't do that if GStreamer 1.16 requires r18b.

What could be the issue here?

EDIT:

I have two different build.gradle files.

Here is the first one:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 28

    defaultConfig {
        applicationId "se.liu.mrleo"
        minSdkVersion 23
        versionCode 1
        versionName "1.0"

        externalNativeBuild {
            ndkBuild {
                def gstRoot
                if (project.hasProperty('gstAndroidRoot'))
                    gstRoot = project.gstAndroidRoot
                else
                    gstRoot = System.env.GSTREAMER_ROOT_ANDROID
                if (gstRoot == null)
                    throw new FileNotFoundException('GSTREAMER_ROOT_ANDROID not set')

                arguments "NDK_APPLICATION_MK=jni/Application.mk",
                        "GSTREAMER_JAVA_SRC_DIR=src",
                        "GSTREAMER_ROOT_ANDROID=$gstRoot",
                        "GSTREAMER_ASSETS_DIR=src/main/assets"

                targets "gstmredge"

                abiFilters  'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64'
            }
        }
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            sourceSets {
                main {
                    manifest.srcFile 'AndroidManifest.xml'
                    java.srcDirs = ['src']
                    resources.srcDirs = ['src']
                    aidl.srcDirs = ['src']
                    renderscript.srcDirs = ['src']
                    res.srcDirs = ['res']
                    assets.srcDirs = ['assets']
                }
            }
        }
    }


    externalNativeBuild {
        ndkBuild {
            path 'jni/Android.mk'
            //path 'jni/Application.mk'
        }
    }

    buildToolsVersion = '28.0.3'
    compileOptions {
        sourceCompatibility = '1.8'
        targetCompatibility = '1.8'
    }
}

afterEvaluate {
    if (project.hasProperty('compileDebugJavaWithJavac')) {
        project.compileDebugJavaWithJavac.dependsOn 'externalNativeBuildDebug'
    }
    if (project.hasProperty('compileReleaseJavaWithJavac')) {
        project.compileReleaseJavaWithJavac.dependsOn 'externalNativeBuildRelease'
    }
}


dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])

    api project(':rtplibrary')

    // Edge
    implementation 'com.obsez.android.lib.filechooser:filechooser:1.1.19'
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support:design:28.0.0'

    // ARCore
    implementation 'de.javagl:obj:0.3.0'
    implementation 'com.google.ar:core:1.9.0'
}

And this is the sencond one;

// 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.6.3'
        classpath 'com.github.dcendents:android-maven-gradle-plugin:2.0'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
        google()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

1

There are 1 best solutions below

0
On

If I'm right in my assumption that the error message is actually "Expected NDK STL shared object" (with the capitalized "NDK" and "STL"), this error is coming from the android gradle plugin:

https://android.googlesource.com/platform/tools/base/+/refs/heads/studio-master-dev/build-system/gradle-core/src/main/java/com/android/build/gradle/internal/ndk/NdkR19Info.kt#31

There is no NdkR18Info. libstdc++ and stlport support was dropped in r18, not r19. This is trivially reproduced by using AGP 3.6 with NDK r18:

* What went wrong:
Execution failed for task ':app:generateJsonModelArm8Debug'.
> Expected NDK STL shared object file at /usr/local/google/home/danalbert/Android/Sdk/ndk/18.1.5063045/sources/cxx-stl/gnu-libstdc++/4.9/libs/armeabi-v7a/libgnustl_shared.so

This is just a bug in the combination of AGP 3.6 (or higher) and NDK r18. You can't use those together. Easiest fix would be to update your NDK (r18 is getting pretty old now anyway; r21b is the latest). Adding ndkVersion "21.1.6352462" to the android block of your build.gradle would do it.

I've sent a patch to fix the bug, but given that no one has reported this issue before it's going to be tough to argue that it's high enough impact to warrant a backport. I'll see if I can at least get it into 4.0 and/or 4.1 though.