1 import java.nio.file.Paths
3 // General gradle arguments for root project
11 // https://developer.android.com/studio/releases/gradle-plugin#updating-gradle
13 // Notice that 4.0.0 here is the version of [Android Gradle Plugin]
14 // Accroding to URL above you will need Gradle 6.1 or higher
16 classpath "com.android.tools.build:gradle:4.1.1"
24 // Project's root where CMakeLists.txt exists: rootDir/support/.cxx -> rootDir
25 def rootDir = Paths.get(project.buildDir.getParent()).getParent()
26 println("rootDir: ${rootDir}")
28 // Output: Shared library (.so) for Android
29 apply plugin: "com.android.library"
31 compileSdkVersion 25 // Android 7.0
34 // - This option controls target platform of module
35 // - The platform might be limited by compiler's support
36 // some can work with Clang(default), but some can work only with GCC...
37 // if bad, both toolchains might not support it
41 // Specify platforms for Application
43 include "arm64-v8a", "armeabi-v7a", "x86_64"
46 ndkVersion "21.3.6528147" // ANDROID_NDK_HOME is deprecated. Be explicit
49 minSdkVersion 21 // Android 5.0+
50 targetSdkVersion 25 // Follow Compile SDK
51 versionCode 34 // Follow release count
52 versionName "7.1.2" // Follow Official version
56 arguments "-DANDROID_STL=c++_shared" // Specify Android STL
57 arguments "-DBUILD_SHARED_LIBS=true" // Build shared object
58 arguments "-DFMT_TEST=false" // Skip test
59 arguments "-DFMT_DOC=false" // Skip document
64 println(externalNativeBuild.cmake.cppFlags)
65 println(externalNativeBuild.cmake.arguments)
68 // External Native build
69 // - Use existing CMakeList.txt
70 // - Give path to CMake. This gradle file should be
71 // neighbor of the top level cmake
75 path "${rootDir}/CMakeLists.txt"
76 // buildStagingDirectory "./build" // Custom path for cmake output
81 // Android Manifest for Gradle
83 manifest.srcFile "AndroidManifest.xml"
87 // https://developer.android.com/studio/build/native-dependencies#build_system_configuration
94 headers "${rootDir}/include"
101 // Instead of `ninja install`, Gradle will deploy the files.
102 // We are doing this since FMT is dependent to the ANDROID_STL after build
104 from "build/intermediates/cmake"
105 into "${rootDir}/libs"
107 // Copy debug binaries
109 from "${rootDir}/libs/debug/obj"
110 into "${rootDir}/libs/debug"
112 // Copy Release binaries
114 from "${rootDir}/libs/release/obj"
115 into "${rootDir}/libs/release"
117 // Remove empty directory
118 delete "${rootDir}/libs/debug/obj"
119 delete "${rootDir}/libs/release/obj"
121 // Copy AAR files. Notice that the aar is named after the folder of this script.
123 from "build/outputs/aar/support-release.aar"
124 into "${rootDir}/libs"
125 rename "support-release.aar", "fmt-release.aar"
128 from "build/outputs/aar/support-debug.aar"
129 into "${rootDir}/libs"
130 rename "support-debug.aar", "fmt-debug.aar"