简体   繁体   English

无法使用Android Studio构建GStreamer教程

[英]Unable to build GStreamer tutorials using Android Studio

I am trying to build the tutorials that are bundled with gstreamer-sdk-android-arm-debug-2013.6 . 我正在尝试构建与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 . src/jni目录(tutorial 1项目)中的Android.mk文件引用了GSTREAMER_SDK_ROOT等环境变量。 From what I have read, Android Studio does not use/pass environment variables to the build scripts. 根据我的阅读,Android Studio不使用/传递环境变量到构建脚本。 Is there a best practice for modifying makefiles and for defining/retrieving the key/value pairs required by the build scripts? 是否有修改makefile和定义/检索构建脚本所需的键/值对的最佳实践?

Ok, I have a working solution. 好的,我有一个有效的解决方案。 You CAN pass environment variables to ndk-build (or any other process spawned by gradle Exec). 您可以将环境变量传递给ndk-build (或由gradle Exec生成的任何其他进程)。 In my case, I wanted to set these for both the clean and build tasks. 就我而言,我想为cleanbuild任务设置这些。 This is is done using tasks.withType(Exec) . 这是使用tasks.withType(Exec) The environment parameter is set here for all Exec tasks. 此处为所有Exec任务设置环境参数。

For GSTREAMER_SDK_ROOT , I added an entry to local.properties : 对于GSTREAMER_SDK_ROOT ,我加入一个条目local.properties

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

For PATH , I used the default for the spawned process and added in what I needed. 对于PATH ,我使用了生成过程的默认值并添加了我需要的内容。

Here is a working version of build.gradle : 这是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'
        }
    }
}

The project now builds and runs. 该项目现在正在构建和运行。 The only other things you will need to do is add ndk.dir to local.properties: 您需要做的唯一其他事情是将ndk.dir添加到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

One more thing: These examples will not build using android-ndk-r10d . 还有一件事:这些示例不会使用android-ndk-r10d Be sure to use android-ndk-r9d . 一定要使用android-ndk-r9d

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM