我使用的CMakeLists.txt如下,我知道就是这个,因为如果我输入错误,就会打印错误。
cmake_minimum_required(VERSION 3.27)
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -u ANativeActivity_onCreate")
set(COMMON_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../common/src")
set(COMMON_HEADERS_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../common/include")
set(GAME_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../game/src")
set(GAME_HEADERS_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../game/include")
#All files that are compiled
file(
GLOB_RECURSE COMMON_SRCS
${COMMON_SOURCE_DIR}/*.cc
${COMMON_SOURCE_DIR}/*.cpp
)
file(
GLOB_RECURSE GAME_SRCS
${GAME_SOURCE_DIR}/*.cc
${GAME_SOURCE_DIR}/*.cpp
)
add_library(
fc
${COMMON_SRCS}
${GAME_SRCS}
)
target_include_directories(
fc PUBLIC
${COMMON_HEADERS_DIR}
${GAME_HEADERS_DIR}
)
target_compile_features(fc PUBLIC cxx_std_20)
target_link_libraries(fc PUBLIC
log
android
)
在cmd中:
#./gradlew assembleDebug
Deprecated Gradle features were used in this build, making it incompatible with Gradle 9.0.
You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.
For more on this, please refer to https://docs.gradle.org/8.5/userguide/command_line_interface.html#sec:command_line_warnings in the Gradle documentation.
BUILD SUCCESSFUL in 2s
34 actionable tasks: 34 executed
我有一个 apk,但我的文件没有被编译,尽管在 生成的 cmake 文件夹的compile_commands.json,我可以读取所有命令来编译我的文件。我手动检查过,有些命令有效。 所以在生成的cmake文件夹中,我找不到我的任何构建文件。
构建.gradle:
plugins {
id 'com.android.application'
}
android {
defaultConfig {
applicationId "com.you.fc"
versionCode 1
versionName "1.0"
externalNativeBuild {
cmake {
cppFlags "-fexceptions -frtti -std=c++20"
arguments "-DANDROID_STL=c++_shared"
abiFilters 'arm64-v8a'
}
}
targetSdk 33
minSdk 22
}
splits {
abi {
enable true
reset()
include "arm64-v8a"
universalApk true
}
}
externalNativeBuild {
cmake {
version "3.27.4"
path file('CMakeLists.txt')
}
}
buildToolsVersion '33.0.0'
ndkPath "/home/me/Desktop/dev/android/android-ndk-r25c/"
compileSdk 33
namespace 'com.you.fc'
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.5.1'
}
你知道发生什么事吗?
Ndk:使用 r26b 和 r25c 进行测试
Gradle:使用 7.5.1 和 8.5 进行测试
CMake:使用 3.18 和 3.27 进行测试
操作系统:Ubuntu 23
我的错,我忘记了 add_library() 中的“共享”
看
https://developer.android.com/studio/projects/configure-cmake