xref: /aosp_15_r20/external/fmtlib/support/build.gradle (revision 5c90c05cd622c0a81b57953a4d343e0e489f2e08)
1import java.nio.file.Paths
2
3// General gradle arguments for root project
4buildscript {
5    repositories {
6        google()
7        jcenter()
8    }
9    dependencies {
10        //
11        // https://developer.android.com/studio/releases/gradle-plugin#updating-gradle
12        //
13        // Notice that 4.0.0 here is the version of [Android Gradle Plugin]
14        // According to URL above you will need Gradle 6.1 or higher
15        //
16        classpath "com.android.tools.build:gradle:4.1.1"
17    }
18}
19repositories {
20    google()
21    jcenter()
22}
23
24// Project's root where CMakeLists.txt exists: rootDir/support/.cxx -> rootDir
25def rootDir = Paths.get(project.buildDir.getParent()).getParent()
26println("rootDir: ${rootDir}")
27
28// Output: Shared library (.so) for Android
29apply plugin: "com.android.library"
30android {
31    compileSdkVersion 25    // Android 7.0
32
33    // Target ABI
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
38    splits {
39        abi {
40            enable true
41            // Specify platforms for Application
42            reset()
43            include  "arm64-v8a", "armeabi-v7a", "x86_64"
44        }
45    }
46    ndkVersion "21.3.6528147" // ANDROID_NDK_HOME is deprecated. Be explicit
47
48    defaultConfig {
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
53
54        externalNativeBuild {
55            cmake {
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
60                cppFlags  "-std=c++17"
61                targets   "fmt"
62            }
63        }
64        println(externalNativeBuild.cmake.cppFlags)
65        println(externalNativeBuild.cmake.arguments)
66    }
67
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
72    externalNativeBuild {
73        cmake {
74            version "3.10.0+"
75            path "${rootDir}/CMakeLists.txt"
76            // buildStagingDirectory "./build"  // Custom path for cmake output
77        }
78    }
79
80    sourceSets{
81        // Android Manifest for Gradle
82        main {
83            manifest.srcFile "AndroidManifest.xml"
84        }
85    }
86
87    // https://developer.android.com/studio/build/native-dependencies#build_system_configuration
88    buildFeatures {
89        prefab true
90        prefabPublishing true
91    }
92    prefab {
93        fmt {
94            headers "${rootDir}/include"
95        }
96    }
97}
98
99assemble.doLast
100{
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
103    copy {
104        from "build/intermediates/cmake"
105        into "${rootDir}/libs"
106    }
107    // Copy debug binaries
108    copy {
109        from "${rootDir}/libs/debug/obj"
110        into "${rootDir}/libs/debug"
111    }
112    // Copy Release binaries
113    copy {
114        from "${rootDir}/libs/release/obj"
115        into "${rootDir}/libs/release"
116    }
117    // Remove empty directory
118    delete "${rootDir}/libs/debug/obj"
119    delete "${rootDir}/libs/release/obj"
120
121    // Copy AAR files. Notice that the aar is named after the folder of this script.
122    copy {
123        from "build/outputs/aar/support-release.aar"
124        into "${rootDir}/libs"
125        rename "support-release.aar", "fmt-release.aar"
126    }
127    copy {
128        from "build/outputs/aar/support-debug.aar"
129        into "${rootDir}/libs"
130        rename "support-debug.aar", "fmt-debug.aar"
131    }
132}
133