【问题标题】:How to use native OpenSL ES in android studio如何在 android studio 中使用原生 OpenSL ES
【发布时间】:2015-04-28 07:27:38
【问题描述】:

我需要使用 Android Studio 在 NDK 中开发一个音频应用。我已经添加了

the ndk path to local.properties -

    ndk.dir=/opt/android-ndk-r10
    sdk.dir=/opt/adt-bundle-linux-x86_64-20140702/sdk

In build.gradle I added an entry for OpenSLES -
apply plugin: 'com.android.application'

android {
    compileSdkVersion 20
    buildToolsVersion "21.1.2"

    defaultConfig {
        applicationId "com.example.hellojni"
        minSdkVersion 8
        targetSdkVersion 21

        ndk {
            moduleName "HelloJNI"
            ldLibs "OpenSLES"       // Link with these libraries!
            stl "stlport_shared"
        }
    }

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

dependencies {
    compile 'com.android.support:support-v4:20.0.0'
    compile 'com.android.support:appcompat-v7:20.0.0'
}

接下来我尝试为 opensl 添加#includes -

#include <SLES/OpenSLES.h>
#include <SLES/OpenSLES_Android.h>

但 IDE 无法识别标头,说它找不到包含文件。我还尝试将本机音频项目导入 android studio,但这也没有编译或运行。我知道官方仍然不支持将 NDK 与 Android Studio 结合使用。但我看过一些视频,展示了如何将 ndk 与 android studio 集成。 有没有办法做到这一点。 提前致谢

【问题讨论】:

    标签: android android-studio android-ndk opensl


    【解决方案1】:

    OpenSL 库可用于具有 API 9+ 的 android 平台,因此您可能需要更改最低要求的 sdk。

    不确定 NDK 如何选择编译哪个平台,但您可能还需要使用自定义 Application.mk 文件自行编译,如下所示:

    APP_ABI := armeabi
    APP_PLATFORM := android-9
    TARGET_PLATFORM := android-9
    

    此外,您应该始终使用最高可用的 sdk 进行定位和编译。

    以下是构建文件的示例:

    android {
        compileSdkVersion 22
        buildToolsVersion "22.0.1"
    
        defaultConfig {
            applicationId "com.example.hellojni"
            minSdkVersion 9
            targetSdkVersion 22
    
            ndk {
                moduleName "HelloJNI"
                ldLibs "OpenSLES"       // Link with these libraries!
                stl "stlport_shared"
            }
        }
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            }
        }
    }
    
    dependencies {
        compile fileTree(dir: 'libs', include: ['*.jar'])
        compile 'com.android.support:appcompat-v7:22.1.1'
    }
    

    注意:通过上述配置,我可以找到库(使用内置 ndk 配置)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-04-28
      • 2016-03-05
      • 1970-01-01
      • 1970-01-01
      • 2012-06-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多