Android studio Android ndk示例本机音频错误

Android studio Android ndk示例本机音频错误,android-studio,android-ndk,opensl,Android Studio,Android Ndk,Opensl,我尝试使用Android Studio中NDK中包含的OpenSl ES的示例代码。 它没有像你稍后看到的那样起作用。所以我需要在Android Studio中使用代码的帮助。 代码是为Eclipse编写的,但我使用了AndroidStudio的导入函数来包含它。我也尝试过Eclipse,效果很好,但是当我在Android Studio中尝试运行代码时,我得到了以下错误代码 /home/flex/AndroidStudioProjects/native-audio1/app/src/main/j

我尝试使用Android Studio中NDK中包含的OpenSl ES的示例代码。 它没有像你稍后看到的那样起作用。所以我需要在Android Studio中使用代码的帮助。 代码是为Eclipse编写的,但我使用了AndroidStudio的导入函数来包含它。我也尝试过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(应用程序)到

进一步,我将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)
my aplication.mk:

APP_ABI := all

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

  • 本地_LDLIBS:=libOpenSLES

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

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

因此,在终端中,我第一次使用命令编译:
ndk build

第二次使用命令时:
ndk build TARGET\u PLATFORM=android xy

xy
必须替换为android版本


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

我想您可能只需要添加

ldLibs.addAll(["OpenSLES"])

build.gradle
文件中的
ndk{}
字段中进行编码。这就为我解决了这个问题。

你能详细说明你的答案吗。我什么也听不懂。
ldLibs.addAll(["OpenSLES"])