Skip to content

Commit

Permalink
Change to audio-echo to use shared lib and add packing workaround in …
Browse files Browse the repository at this point in the history
…CMakeLists.txt
ggfan committed Sep 22, 2016
1 parent 78f9252 commit 5ba31b2
Showing 5 changed files with 55 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@
local.properties
build
*~
externalNativeBuild
.externalNativeBuild
libwebp
.DS_Store

3 changes: 1 addition & 2 deletions audio-echo/README.md
Original file line number Diff line number Diff line change
@@ -3,8 +3,7 @@ Audio-Echo
The sample demos how to use OpenSL ES to create a player and recorder in Android Fast Audio Path, and connect them to loopback audio. On most android devices, there is a optimized audio path that is tuned up for low latency purpose. The sample creates player/recorder to work in this highly optimized audio path(sometimes called native audio path, [low latency path](http://stackoverflow.com/questions/14842803/low-latency-audio-playback-on-android?rq=1), or fast audio path). The application is validated against the following configurations:
* Android L AndroidOne
* Android M Nexus 5, Nexus 9

This sample uses the new Android Studio with CMake support.
This sample uses the new Android Studio with CMake support, and shows how to use shared stl lib with android studio version 2.2.0, see CMakeLists.txt for details

Pre-requisites
--------------
6 changes: 4 additions & 2 deletions audio-echo/app/build.gradle
Original file line number Diff line number Diff line change
@@ -15,8 +15,10 @@ android {
}
externalNativeBuild {
cmake {
arguments '-DANDROID_STL=gnustl_static', '-DANDROID_TOOLCHAIN=gcc',
'-DABDRIOID_PLATFORM=21'
// With android studio 2.2.0 +cmake, app needs to pack shared lib to
// into APK. Refer to CMakeLists.txt for details
arguments '-DANDROID_STL=c++_shared', '-DANDROID_TOOLCHAIN=clang',
'-DANDROID_PLATFORM=android-21'
}
}
}
10 changes: 9 additions & 1 deletion audio-echo/app/src/main/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -8,5 +8,13 @@ set(echo_SRCS debug_utils.cpp
audio_main.cpp)
add_library(echo SHARED ${echo_SRCS})

# Include libraries needed for hello-jni lib
# include libraries needed for hello-jni lib
target_link_libraries(echo android log OpenSLES atomic)

# Android Studio 2.2.0 with CMake support does not pack stl shared libraries,
# so app needs to pack the right shared lib into APK. This sample uses solution
# from https://github.com/jomof/ndk-stl to find the right stl shared lib to use
# and copy it to the right place for Android Studio to pack
# Usage: download ndk-stl-config.cmake into app's directory hosting CMakeLists.txt
# and just use it with the following line
include(ndk-stl-config.cmake)
40 changes: 40 additions & 0 deletions audio-echo/app/src/main/cpp/ndk-stl-config.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Copy shared STL files to Android Studio output directory so they can be
# packaged in the APK.
# Usage:
#
# find_package(ndk-stl REQUIRED)
#
# or
#
# find_package(ndk-stl REQUIRED PATHS ".")

if(NOT ${ANDROID_STL} MATCHES "_shared")
return()
endif()

function(configure_shared_stl lib_path so_base)
message("Configuring STL ${so_base} for ${ANDROID_ABI}")
configure_file(
"${ANDROID_NDK}/sources/cxx-stl/${lib_path}/libs/${ANDROID_ABI}/lib${so_base}.so"
"${CMAKE_LIBRARY_OUTPUT_DIRECTORY}/lib${so_base}.so"
COPYONLY)
endfunction()

if("${ANDROID_STL}" STREQUAL "libstdc++")
# The default minimal system C++ runtime library.
elseif("${ANDROID_STL}" STREQUAL "gabi++_shared")
# The GAbi++ runtime (shared).
message(FATAL_ERROR "gabi++_shared was not configured by ndk-stl package")
elseif("${ANDROID_STL}" STREQUAL "stlport_shared")
# The STLport runtime (shared).
configure_shared_stl("stlport" "stlport_shared")
elseif("${ANDROID_STL}" STREQUAL "gnustl_shared")
# The GNU STL (shared).
configure_shared_stl("gnu-libstdc++/4.9" "gnustl_shared")
elseif("${ANDROID_STL}" STREQUAL "c++_shared")
# The LLVM libc++ runtime (static).
configure_shared_stl("llvm-libc++" "c++_shared")
else()
message(FATAL_ERROR "STL configuration ANDROID_STL=${ANDROID_STL} is not supported")
endif()

0 comments on commit 5ba31b2

Please sign in to comment.