【问题标题】:Android ndk example native-audio errorAndroid ndk 示例原生音频错误
【发布时间】:2015-07-30 15:04:09
【问题描述】:

我尝试使用 OpenSl ES 的示例代码,它包含在 Android Studio 的 NDK 中。 正如您稍后将看到的那样,它不起作用。所以我需要帮助才能使用 Android Studio 中的代码。 该代码是为 Eclipse 编写的,但我使用了 Android Studio 中的导入功能来包含它。我也尝试了 Eclipse,它运行良好,但是当尝试在 Android Studio 中运行代码时,我得到以下错误代码

/home/flex/AndroidStudioProjects/native-audio1/app/src/main/jni/native-audio-jni.c
Error:(155) undefined reference to `slCreateEngine'
Error:(165) undefined reference to `SL_IID_ENGINE'
Error:(165) undefined reference to `SL_IID_ENGINE'
Error:(170) undefined reference to `SL_IID_ENVIRONMENTALREVERB'
Error:(170) undefined reference to `SL_IID_ENVIRONMENTALREVERB'
Error:(215) undefined reference to `SL_IID_BUFFERQUEUE'
Error:(215) undefined reference to `SL_IID_EFFECTSEND'
Error:(215) undefined reference to `SL_IID_VOLUME'
Error:(215) undefined reference to `SL_IID_BUFFERQUEUE'

...

collect2: error: ld returned 1 exit status
make: *** [/home/flex/AndroidStudioProjects/native-audio1/app/build/intermediates/ndk/debug/obj/local/arm64-v8a/libnative-audio-jni.so] Error 1
Error:Execution failed for task ':app:compileDebugNdk'.
> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/home/flex/android-ndk-r10e/ndk-build'' finished with non-zero exit value 2
Information:BUILD FAILED
Information:Total time: 2.942 secs
Information:38 errors
Information:0 warnings
Information:See complete output in console

到目前为止我做了什么: 我变了 build.gradle (app) 到

apply plugin: 'com.android.application'

android {
    compileSdkVersion 21
    buildToolsVersion "21.1.2"

    defaultConfig {
        applicationId "com.example.nativeaudio"
        minSdkVersion 19
        targetSdkVersion 19

        ndk {
            moduleName "native-audio-jni" //I included this one
        }
    }

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

}

我进一步将 local.properties 更改为

sdk.dir=/home/flex/Android/Sdk
ndk.dir=/home/flex/android-ndk-r10e

我的 Android.mk 看起来像这样

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE    := native-audio-jni
LOCAL_SRC_FILES := native-audio-jni.c
# for native audio
LOCAL_LDLIBS    += -lOpenSLES
# for logging
LOCAL_LDLIBS    += -llog
# for native asset manager
LOCAL_LDLIBS    += -landroid

include $(BUILD_SHARED_LIBRARY)

我的应用程序.mk:

APP_ABI := all

【问题讨论】:

    标签: android-studio android-ndk opensl


    【解决方案1】:

    解决方案是编译源代码两次。

    所以在终端中我第一次使用命令编译:ndk-build
    而我第二次使用的命令:ndk-build TARGET_PLATFORM=android-xy
    xy必须换成android版本

    这绝对不是正确的方法,但至少它使它起作用了。

    【讨论】:

    • 您能否详细说明您的答案。我对此一无所知。
    【解决方案2】:

    我想你可能只需要添加

    ldLibs.addAll(["OpenSLES"])
    

    插入build.gradle 文件中的ndk{ } 字段。这就是为我解决问题的方法。

    【讨论】:

      【解决方案3】:

      我从未在 Android 上尝试过 OpenSL ES,但也许您可以尝试将 LOCAL_LDLIBS 更改为(根据this 站点):

      • LOCAL_LDLIBS := libOpenSLES

      也许还可以尝试为每个平台一次构建一个步骤(不是 APP_ABI 中的“全部”)

      【讨论】:

        猜你喜欢
        • 2011-10-16
        • 1970-01-01
        • 2014-02-21
        • 2016-12-26
        • 1970-01-01
        • 1970-01-01
        • 2019-03-20
        • 2016-09-08
        • 1970-01-01
        相关资源
        最近更新 更多