]>
Commit | Line | Data |
---|---|---|
20effc67 | 1 | import java.nio.file.Paths |
eafe8130 | 2 | |
11fdf7f2 TL |
3 | // General gradle arguments for root project |
4 | buildscript { | |
5 | repositories { | |
6 | google() | |
7 | jcenter() | |
8 | } | |
11fdf7f2 | 9 | dependencies { |
eafe8130 | 10 | // |
20effc67 | 11 | // https://developer.android.com/studio/releases/gradle-plugin#updating-gradle |
eafe8130 | 12 | // |
20effc67 TL |
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 | |
eafe8130 | 15 | // |
20effc67 | 16 | classpath "com.android.tools.build:gradle:4.1.1" |
11fdf7f2 TL |
17 | } |
18 | } | |
eafe8130 TL |
19 | repositories { |
20 | google() | |
21 | jcenter() | |
22 | } | |
11fdf7f2 | 23 | |
20effc67 TL |
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}") | |
27 | ||
28 | // Output: Shared library (.so) for Android | |
29 | apply plugin: "com.android.library" | |
11fdf7f2 TL |
30 | android { |
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 | |
11fdf7f2 TL |
41 | // Specify platforms for Application |
42 | reset() | |
eafe8130 | 43 | include "arm64-v8a", "armeabi-v7a", "x86_64" |
11fdf7f2 TL |
44 | } |
45 | } | |
20effc67 | 46 | ndkVersion "21.3.6528147" // ANDROID_NDK_HOME is deprecated. Be explicit |
11fdf7f2 TL |
47 | |
48 | defaultConfig { | |
49 | minSdkVersion 21 // Android 5.0+ | |
50 | targetSdkVersion 25 // Follow Compile SDK | |
20effc67 TL |
51 | versionCode 34 // Follow release count |
52 | versionName "7.1.2" // Follow Official version | |
11fdf7f2 TL |
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 | |
eafe8130 | 60 | cppFlags "-std=c++17" |
20effc67 | 61 | targets "fmt" |
11fdf7f2 TL |
62 | } |
63 | } | |
11fdf7f2 TL |
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 { | |
20effc67 TL |
74 | version "3.10.0+" |
75 | path "${rootDir}/CMakeLists.txt" | |
11fdf7f2 TL |
76 | // buildStagingDirectory "./build" // Custom path for cmake output |
77 | } | |
11fdf7f2 TL |
78 | } |
79 | ||
80 | sourceSets{ | |
81 | // Android Manifest for Gradle | |
82 | main { | |
20effc67 TL |
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" | |
11fdf7f2 TL |
95 | } |
96 | } | |
97 | } | |
98 | ||
99 | assemble.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 { | |
20effc67 TL |
104 | from "build/intermediates/cmake" |
105 | into "${rootDir}/libs" | |
11fdf7f2 TL |
106 | } |
107 | // Copy debug binaries | |
108 | copy { | |
20effc67 TL |
109 | from "${rootDir}/libs/debug/obj" |
110 | into "${rootDir}/libs/debug" | |
11fdf7f2 TL |
111 | } |
112 | // Copy Release binaries | |
113 | copy { | |
20effc67 TL |
114 | from "${rootDir}/libs/release/obj" |
115 | into "${rootDir}/libs/release" | |
11fdf7f2 TL |
116 | } |
117 | // Remove empty directory | |
20effc67 TL |
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 | } | |
11fdf7f2 | 132 | } |