Files

131 lines
3.5 KiB
Groovy
Raw Permalink Normal View History

2020-11-17 23:31:06 +09:00
import java.nio.file.Paths
2018-11-06 10:08:46 +09:00
2018-03-12 19:40:25 +00:00
// General gradle arguments for root project
buildscript {
repositories {
google()
2026-01-22 11:24:08 -08:00
mavenCentral()
2018-03-12 19:40:25 +00:00
}
dependencies {
2026-01-21 23:52:00 +05:30
classpath "com.android.tools.build:gradle:9.0.0"
2018-03-12 19:40:25 +00:00
}
}
2018-11-02 16:54:00 +00:00
repositories {
google()
2026-01-22 11:24:08 -08:00
mavenCentral()
2018-11-02 16:54:00 +00:00
}
2018-03-12 19:40:25 +00:00
2020-11-17 23:31:06 +09:00
// Project's root where CMakeLists.txt exists: rootDir/support/.cxx -> rootDir
2026-01-21 23:52:00 +05:30
2020-11-17 23:31:06 +09:00
def rootDir = Paths.get(project.buildDir.getParent()).getParent()
println("rootDir: ${rootDir}")
2026-01-21 23:52:00 +05:30
// Output: Shared library (.so) for Android
2020-11-17 23:31:06 +09:00
apply plugin: "com.android.library"
2018-03-12 19:40:25 +00:00
android {
2026-01-21 23:52:00 +05:30
namespace = "dev.fmt"
2026-01-22 11:24:08 -08:00
compileSdk 36 // Target Android 16 (API 36).
2026-01-21 23:52:00 +05:30
/* Target ABI
- This option controls target platform of module
- The platform might be limited by compiler's support
some can work with Clang(default), but some can work only with GCC...
if bad, both toolchains might not support it
*/
2026-01-22 11:24:08 -08:00
ndkVersion = "28.2.13676358"
2018-03-12 19:40:25 +00:00
defaultConfig {
2026-01-22 11:24:08 -08:00
minSdk 21 // Android 5.0+
targetSdkVersion 36 // Follow Compile SDK
2020-11-17 23:31:06 +09:00
versionCode 34 // Follow release count
versionName "7.1.2" // Follow Official version
2026-01-21 23:52:00 +05:30
ndk{
abiFilters "arm64-v8a", "armeabi-v7a", "x86_64"
}
2018-03-12 19:40:25 +00:00
externalNativeBuild {
cmake {
arguments "-DANDROID_STL=c++_shared" // Specify Android STL
arguments "-DBUILD_SHARED_LIBS=true" // Build shared object
arguments "-DFMT_TEST=false" // Skip test
2026-01-22 11:24:08 -08:00
arguments "-DFMT_DOC=false" // Skip documentation
2018-11-02 16:54:00 +00:00
cppFlags "-std=c++17"
2020-11-17 23:31:06 +09:00
targets "fmt"
2018-03-12 19:40:25 +00:00
}
}
println(externalNativeBuild.cmake.cppFlags)
println(externalNativeBuild.cmake.arguments)
}
// External Native build
// - Use existing CMakeList.txt
// - Give path to CMake. This gradle file should be
// neighbor of the top level cmake
externalNativeBuild {
cmake {
2026-01-22 11:24:08 -08:00
version = "3.22.1"
2020-11-17 23:31:06 +09:00
path "${rootDir}/CMakeLists.txt"
2018-03-12 19:40:25 +00:00
// buildStagingDirectory "./build" // Custom path for cmake output
}
}
sourceSets{
// Android Manifest for Gradle
main {
2020-11-17 23:31:06 +09:00
manifest.srcFile "AndroidManifest.xml"
}
}
// https://developer.android.com/studio/build/native-dependencies#build_system_configuration
buildFeatures {
2026-01-21 23:52:00 +05:30
prefab = true
prefabPublishing = true
2020-11-17 23:31:06 +09:00
}
prefab {
fmt {
2026-01-21 23:52:00 +05:30
headers = "${rootDir}/include"
2018-03-12 19:40:25 +00:00
}
}
}
assemble.doLast
{
2026-01-21 23:52:00 +05:30
/*
*- Instead of `ninja install`, Gradle will deploy the files.
*- We are doing this since FMT is dependent to the ANDROID_STL after build
*/
2018-03-12 19:40:25 +00:00
copy {
2020-11-17 23:31:06 +09:00
from "build/intermediates/cmake"
into "${rootDir}/libs"
2018-03-12 19:40:25 +00:00
}
// Copy debug binaries
copy {
2020-11-17 23:31:06 +09:00
from "${rootDir}/libs/debug/obj"
into "${rootDir}/libs/debug"
2018-03-12 19:40:25 +00:00
}
// Copy Release binaries
copy {
2020-11-17 23:31:06 +09:00
from "${rootDir}/libs/release/obj"
into "${rootDir}/libs/release"
2018-03-12 19:40:25 +00:00
}
// Remove empty directory
2020-11-17 23:31:06 +09:00
delete "${rootDir}/libs/debug/obj"
delete "${rootDir}/libs/release/obj"
// Copy AAR files. Notice that the aar is named after the folder of this script.
copy {
from "build/outputs/aar/support-release.aar"
into "${rootDir}/libs"
rename "support-release.aar", "fmt-release.aar"
}
copy {
from "build/outputs/aar/support-debug.aar"
into "${rootDir}/libs"
rename "support-debug.aar", "fmt-debug.aar"
}
2018-03-12 19:40:25 +00:00
}