无法使用 Android Studio 构建 GStreamer 教程 [英] Unable to build GStreamer tutorials using Android Studio

查看:28
本文介绍了无法使用 Android Studio 构建 GStreamer 教程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试构建与 gstreamer-sdk-android-arm-debug-2013.6 捆绑的教程.src/jni目录下的Android.mk文件(教程1项目)引用了GSTREAMER_SDK_ROOT等环境变量.据我所知,Android Studio 不会使用/将环境变量传递给构建脚本.是否有修改 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-build(或由 gradle Exec 产生的任何其他进程).就我而言,我想为 cleanbuild 任务设置这些.这是使用 tasks.withType(Exec) 完成的.此处为所有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_ROOT,我在 local.properties 中添加了一个条目:

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

gst.dir=/Users/svenyonson/sdk/gstreamer-sdk-android-arm-debug-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

还有一点:这些示例不会使用 android-ndk-r10d 构建.一定要使用android-ndk-r9d.

One more thing: These examples will not build using android-ndk-r10d. Be sure to use android-ndk-r9d.

这篇关于无法使用 Android Studio 构建 GStreamer 教程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆