Issue
The CMakeLists.txt I used is below, I know it is this one, because if I mistype something, an error is printed.
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
)
And in 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
I have got an apk, but no file of mine is getting compiled, although in compile_commands.json of cmake folder generated, I can read all the commands to compile my files. I have checked it manually, some commands are working. So in the cmake folder generating, I can't find any built file of mine.
build.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'
}
Do you know what is going on ?
Ndk : tested with r26b and r25c
Gradle: tested with 7.5.1 and 8.5
CMake: tested with 3.18 and 3.27
OS: Ubuntu 23
Solution
Adding SHARED
to add_library()
solved the problem.
Resource: https://developer.android.com/studio/projects/configure-cmake
Answered By - Nathan Answer Checked By - Terry (WPSolving Volunteer)