gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 18:34:15 27 4
gpt4 key购买 nike

我正在用双簧管开始一个新项目。我在 Github/Oboe 上使用完全相同的 CMakeLists.txt .

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

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

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

我已经阅读了 NDK CMake 指南,并搜索了很多带有错误“无法为目标 'xxxxxxx' 指定链接库,它不是由该项目构建的”的 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>")

您必须定义所有包含目录并链接构建文件,此外您还必须将 gradle 文件与此 CMakeLits.txt 链接

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

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

关于android - 我在哪里可以找到用于双簧管的新 android studio 项目的工作 CMakeLists.txt?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54939099/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com