Update your build settings for Oboe

There are two ways to incorporate the Oboe library into your project.

Integrate Oboe with Gradle and CMake

These instructions are for projects using Android Gradle plugin version 4.1.0 or higher using native dependencies with CMake.

If your project is using either the Android Gradle plugin version 4.0 or ndk-build instead of CMake, the process is slightly different. See Using native dependencies.

Update build.gradle

To add Oboe to your app while using Android Gradle plugin version 4.1.0 or higher, make the following additions to your app's build.gradle file.

  1. Add the oboe dependency to the dependencies section. If necessary, replace 1.5.0 with the latest stable version of Oboe:

    dependencies {
        implementation 'com.google.oboe:oboe:1.5.0'
    }
    
  2. Enable the prefab option in the buildFeatures section.

    android {
        buildFeatures {
            prefab true
        }
    }
    
  3. Configure your app to use the shared STL:

    android {
        defaultConfig {
            externalNativeBuild {
                cmake {
                    arguments "-DANDROID_STL=c++_shared"
                }
            }
        }
    }
    

Update CMakeLists.txt

Adding Oboe requires two additions to your app's CMakeLists.txt file.

  1. Add the following find_package command:

    find_package (oboe REQUIRED CONFIG)
    
  2. Add oboe::oboe to the list of libraries passed to the target_link_libraries command associated with your main executable.

Integrate with the Android Game SDK

  1. Download the library and check it into your source control system.

  2. Make the following changes to your project's build settings.

Static library

When you integrate with the Android Game SDK, you statically link to a version of the Oboe library compiled for the given ABI, API level, NDK, and STL combination:

  1. Add gamesdk/include to your compiler include paths.
  2. Add a path of the following form in your linker library paths:

    gamesdk/libs/architecture_APIapiLevel_NDKndkVersion_stlVersion_Release
    

    For example: gamesdk/libs/arm64-v8a_API24_NDK18_cpp_static_Release

  3. Add -loboe_static to your linker command.

You don't need to bundle the liboboe.so shared library, which means static linking gives you a much smaller code footprint.

Shared library

If the ABI, API level, NDK, and STL combination required for a static library isn't available for your settings, you can link against the shared library instead:

  1. Follow steps 1 and 2 from the previous section (about the static library) to update your compiler include paths, and use the appropriate header file.

  2. Add a path of the following form in your linker library paths:

    gamesdk/libs/architectureAPIapiLevelNDKndkVersion_stlVersion_Release/lib/oboe

  3. Add -loboe -lOpenSLES to your linker command.

Using CMake (static library only)

If you're using CMake, see the gamesdk/samples/bouncyball/app/CMakeLists.txt file in the downloaded SDK for an example CMake configuration. It includes a utility file called gamesdk/samples/gamesdk.cmake, which performs final checks, adds the proper compiler include paths, and generates a target that you can use to link the library.

To use the gamesdk.cmake utility:

  1. Include this file in your CMakeLists.txt:

    // Use a relative or absolute path. For example, /home/yourusername/gamesdk
    // or C:\Android\gamesdk.
    include("path/to/gamesdk/samples/gamesdk.cmake")
    
  2. Call the add_gamesdk_target function with the folder containing the gamesdk:

    // Use a relative or absolute path.
    add_gamesdk_target(PACKAGE_DIR path/to/gamesdk)
    
  3. In your target_link_libraries for your native library, add oboe as a dependency:

    // The casing of OpenSLES is important.
    target_link_libraries(native-lib oboe OpenSLES ...) 
    

For advanced usage of CMake, see the gamesdk.cmake source file.

Next steps: using Oboe

To play or record audio with Oboe, create and activate one or more audio streams, and use callbacks to exchange audio between your audio input/output devices and your app. See Using Oboe.