我在哪里可以找到一个 CMakeLists.txt 用于双簧管的新 android 工作室项目?

Where can I find a working CMakeLists.txt for new android studio project with oboe?

我正在用双簧管开始一个新项目。我在 Github/Oboe.

上使用完全相同的 CMakeLists.txt

老实说,这是我的第一个 android 本机项目。我对 C++ 有扎实的了解,但我一生中从未使用过 CMake。我已经尝试了好几个小时 "fix" 示例 CMakeLists.txt 文件(到处研究以了解每一行的作用),但它很累,因为我就像玻璃器皿上的大象。每次我触摸一行,错误"mutates"因为我。

我的目标不是学习 CMake(至少现在是这样,尽管在不久的将来我肯定会需要它),而是让库正常工作,这样我就可以开始做事了。

所以这是我的问题:我在哪里可以找到 CMakeLists.txt 的工作副本,将双簧管作为单一依赖项开始制造噪音? 如果它根本不存在并且我必须在进行本机编程之前一定要学习 CMake 相关的东西,那么任何起点或建议都将受到高度赞赏。

我已经阅读了 NDK CMake 指南,并搜索了很多带有错误 "Cannot specify link libraries for target 'xxxxxxx' which is not built by this project" 的 SO 问题,但即使从双簧管 CMakeLists.txt 文件中也出现了这个错误。

提前致谢。

如果可以的话可能会更顺利:

CMakeLists.txt 是 gradle 的一种桥梁,可以用来获取您想要在应用中使用的所有原生内容。

这是我的示例 CMakeLists.txt,它适用于双簧管集成。

# 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>")

您必须定义所有包含目录以及 link 构建文件,除此之外您还必须 link gradle 文件 CMakeLits.txt

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

最后你还应该注意文件是否在正确的位置,这样项目结构应该看起来像 this.