Add OpenSL to android

765 views Asked by At

im very confused with NDK and with OpenSL Im trying to add OpenSL to my project. And have some problems. When i create ndk project- i dont have file Android.mk but i have CMakeList

in tutorials everywhere talks about android.mk where need write one string for implement OpenSL to project.

here my build.graddle(module) file

android {
    compileSdkVersion 26
    buildToolsVersion "26.0.1"

    defaultConfig {
        minSdkVersion 15
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    externalNativeBuild {
        cmake {
            path 'CMakeLists.txt'
        }
    }

    sourceSets {
        main {
            jniLibs.srcDirs 'imported-lib/src/', 'more-imported-libs/src/'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:26.+'
}

CMakeList.txt

cmake_minimum_required(VERSION 3.4.1)
add_library( # Specifies the name of the library.
             native-lib

             # Sets the library as a shared library.
             SHARED

             # Provides a relative path to your source file(s).
             src/main/cpp/native-lib.cpp )

             # Specifies a path to native header files.
             include_directories(src/main/cpp/include/)

             # Include libraries needed for native-audio-jni lib
             target_link_libraries(native-audio-jni
                                   android
                                   log
                                   OpenSLES)

and a simple test for ndk

#include <jni.h>
#include <string>

extern "C"
JNIEXPORT jstring JNICALL
Java_ndk_test_stringFromJNI(
        JNIEnv *env,
        jobject /* this */) {
    std::string hello = "Hello from C++";
    return env->NewStringUTF(hello.c_str());
}

calling function stringFromJNI is ok i see this line in logs. But main question what im doing wrong. How to implement OpenSL without Android.mk

In google.devandroid section its tell add LOCAL_LDLIBS += -lOpenSLES to Android.mk in every tutorial all tells about android.mk. But i dont have this file. Can any help me ? in example of goolink to example

1

There are 1 answers

0
AudioBubble On

I suggest adding this to source file or .h file:

#include "OpenSLES.h"
#include "OpenSLES_Android.h"
#include "OpenSLES_AndroidConfiguration.h"

I've based my solution around this example: https://android.googlesource.com/platform/system/media/+/bd2fc031926582ee8b0df40673c66dfa4cc45a61/opensles/tests/examples/slesTestRecBuffQueue.cpp

and in the CMakeList.txt:

target_link_libraries(
                      android
                      OpenSLES)