3

I'm starting a new project with oboe. I'm using the exact same CMakeLists.txt on Github/Oboe.

To be honest, this is my first android native project. I have solid knowledge of C++, but I've never used CMake in my life. I've been trying for hours to "fix" the sample CMakeLists.txt file (Researching everywhere to understand what does every single line do), but it's exhausting as I'm like an elephant on a glassware. Every time I touch a line, the error "mutates" because of me.

My goal here is not to learn CMake (At least for now, although I'll need it for sure on the near future) but to get the lib working, so I can start getting things done.

So here's my question: Where can I find a working copy of CMakeLists.txt with oboe as a single dependency to start making noise? If it simply doesn't exists and I MUST definitely learn CMake related stuff before making any move on native programming, then any starting point or suggestion will be highly appreciated.

I already read the NDK CMake guide, and searched lots of SO questions with the error "Cannot specify link libraries for target 'xxxxxxx' which is not built by this project" but this error is rising even from the oboe CMakeLists.txt file.

Thanks in advance.

Raymond Arteaga
  • 4,355
  • 19
  • 35
  • 1
    If you use the same structure as on the page you linked to, you'll need (at least) two CMakeLists.txt files; one for your own library, and one for Oboe itself. Though the latter one you'd just take from the github repo. Did you set up your directory structure the same way as they did in that sample CMakeLists.txt? What are the exact error message(s) you're getting? – Michael Mar 01 '19 at 06:42
  • I'm using this https://pastebin.com/X2jmzP6r and it gives me a sources error(Sources not found), I commented the line 4 and thn the error becomes: "Cannot specify link libraries for target "native-lib" which is not built by this project", then I delete "native-lib" and "log" from target_link_libraries() and still gives me the same error with oboe. – Raymond Arteaga Mar 01 '19 at 07:15
  • Sorry, but asking for off-site resources (like examples) is **off-topic** on Stack Overflow. Instead, show your attempt (code and the error message) so we could help you. – Tsyvarev Mar 01 '19 at 07:49
  • 1
    _"it gives me a sources error(Sources not found), I commented the line 4"_ Oboe is a library you would use from native code, so you need some native code of your own. – Michael Mar 01 '19 at 09:20

2 Answers2

3

CMakeLists.txt is sort of a bridge for gradle to pick up all the native stuff that you want to use in your app.

Here is my example CMakeLists.txt which is working just fine for oboe integration.

# For more information about using CMake with Android Studio, read the
# documentation: https://d.android.com/studio/projects/add-native-code.html

# Sets the minimum version of CMake required to build the native library.

cmake_minimum_required(VERSION 3.4.1)

include_directories(third_party)
include_directories(src/main/cpp/)

# Creates and names a library, sets it as either STATIC
# or SHARED, and provides the relative paths to its source code.
# You can define multiple libraries, and CMake builds them for you.
# Gradle automatically packages shared libraries with your APK.

add_library( # Sets the name of the library.
        audio-native-lib

        # Sets the library as a shared library.
        SHARED

        # Provides a relative path to your source file(s).
        #${audiosupport_sources}
        # main game files
        src/main/cpp/audio-support.cpp
        src/main/cpp/main/AudioPlayer.cpp

        # audio engine
        src/main/cpp/audio/AAssetDataSource.cpp
        src/main/cpp/audio/Player.cpp

        # UI engine
        src/main/cpp/ui/OpenGLFunctions.cpp

        # utility functions
        src/main/cpp/utils/logging.h
        src/main/cpp/utils/UtilityFunctions.cpp
        )


set (TARGET_LIBS log android oboe GLESv2)
MESSAGE(STATUS "Using NDK media extractor")
add_definitions(-DUSE_FFMPEG=0)
target_sources( audio-native-lib PRIVATE src/main/cpp/audio/NDKExtractor.cpp )
set (TARGET_LIBS ${TARGET_LIBS} mediandk)

# Specifies libraries CMake should link to your target library. You
# can link multiple libraries, such as libraries you define in this
# build script, prebuilt third-party libraries, or system libraries.
target_link_libraries( audio-native-lib ${TARGET_LIBS} )

# Set the path to the Oboe directory.
# TODO change this to where you downloaded oboe library
set (OBOE_DIR /Users/MyUser/Documents/repos/android_audio/oboe)
# Add the Oboe library as a subdirectory in your project.
# add_subdirectory tells CMake to look in this directory to
# compile oboe source files using oboe's CMake file.
# ./oboe specifies where the compiled binaries will be stored
add_subdirectory (${OBOE_DIR} ./oboe-bin)



target_compile_options(audio-native-lib
        PRIVATE -std=c++14 -Wall -Werror "$<$<CONFIG:RELEASE>:-Ofast>")

You have to define all the include directories and also link the build files and in addition to that you have to link the gradle file with this CMakeLits.txt

externalNativeBuild {
    cmake {
        path file('CMakeLists.txt')
    }
}
sourceSets {
    main {
        jniLibs.srcDirs = ['libs']
    }
}

Finally you should also be careful about files being at the right place so project structure should look like this.

Atif Rehman
  • 106
  • 8
1

It might more smooth if you could:

Gerry
  • 1,223
  • 9
  • 17