无法建立采用Android工作室的GStreamer教程工作室、教程、Android、GStreamer

2023-09-05 02:12:57 作者:三分鐘熱度

我想建立捆绑在一起的GStreamer-SDK-机器人臂,调试2013.6 的教程。该 Android.mk 文件中的的src / JNI 目录(教程1项目)引用环境变量,例如 GSTREAMER_SDK_R​​OOT 。从我已阅读,Android的工作室不使用/环境变量传递给构建脚本。有没有修改的makefile和定义/检索由构建脚本所需的键/值对的最佳做法?

I am trying to build the tutorials that are bundled with gstreamer-sdk-android-arm-debug-2013.6. The Android.mk file in the src/jni directory (tutorial 1 project) references environment variables such as GSTREAMER_SDK_ROOT. From what I have read, Android Studio does not use/pass environment variables to the build scripts. Is there a best practice for modifying makefiles and for defining/retrieving the key/value pairs required by the build scripts?

推荐答案

好吧,我有一个有效的解决方案。你可以通过环境变量 NDK建造(或摇篮Exec的衍生任何其他进程)。就我而言,我想这些设置为这两个洁净建立任务。这是通过使用 tasks.withType(执行)。环境参数被设置在这里的所有Exec的任务。

Ok, I have a working solution. You CAN pass environment variables to ndk-build (or any other process spawned by gradle Exec). In my case, I wanted to set these for both the clean and build tasks. This is is done using tasks.withType(Exec). The environment parameter is set here for all Exec tasks.

有关 GSTREAMER_SDK_R​​OOT ,我添加一个条目,以 local.properties

For GSTREAMER_SDK_ROOT, I added an entry to local.properties:

gst.dir = /用户/ svenyonson / SDK / GStreamer的-SDK-机器人臂,调试2013.6

有关 PATH ,我使用的是默认的衍生过程,在什么我需要添加。

For PATH, I used the default for the spawned process and added in what I needed.

下面是一个工作版本 build.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 19
    buildToolsVersion "20.0.0"

    defaultConfig {
        applicationId "com.gst_sdk_tutorials.tutorial_1"
        minSdkVersion 19
        targetSdkVersion 19
    }

    sourceSets.main {
        jni.srcDirs = []
        jniLibs.srcDir 'src/main/libs'
        java.srcDirs += 'src/main/jni/src'
    }

    tasks.withType(Exec) {

        def localProperties = new Properties()
        localProperties.load(project.rootProject.file('local.properties').newDataInputStream())
        def gstDir = localProperties.getProperty('gst.dir')

        environment = [:]
        environment['PATH'] = System.getenv("PATH")+ ":/usr/local/bin"
        environment['GSTREAMER_SDK_ROOT'] = gstDir
    }


    task buildNative(type: Exec, description: 'Compile JNI source via NDK') {

        def ndkDir = project.plugins.findPlugin('com.android.application').getNdkFolder()
        commandLine "$ndkDir/ndk-build",
            '-C', file('src/main/jni').absolutePath,
            '-j', Runtime.runtime.availableProcessors(),
            'all',
            'NDK_DEBUG=1',
            'V=1',
            'APP_PLATFORM=android-19'

    }

    task cleanNative(type: Exec, description: 'Clean JNI object files') {
        def ndkDir = project.plugins.findPlugin('com.android.application').getNdkFolder()
        commandLine "$ndkDir/ndk-build",
            '-C', file('src/main/jni').absolutePath,
            'clean'
    }

    clean.dependsOn 'cleanNative'

    tasks.withType(JavaCompile) {
        compileTask -> compileTask.dependsOn buildNative
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }
}

该项目现在构建并运行。你需要做的唯一其他的事情就是添加 ndk.dir 来local.properties:

The project now builds and runs. The only other things you will need to do is add ndk.dir to local.properties:

sdk.dir=/Users/svenyonson/sdk/android-sdk
ndk.dir=/Users/svenyonson/sdk/android-ndk-r9d
gst.dir=/Users/svenyonson/sdk/gstreamer-sdk-android-arm-debug-2013.6

一件事:这些例子不会建立使用的Andr​​oid NDK-r10d 。一定要使用的Andr​​oid NDK-r9d