• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1
2// General gradle arguments for root project
3buildscript {
4    repositories {
5        google()
6        jcenter()
7    }
8    dependencies {
9        //
10        // https://developer.android.com/studio/releases/gradle-plugin
11        //
12        // Notice that 3.3.0 here is the version of [Android Gradle Plugin]
13        // Accroding to URL above you will need Gradle 5.0 or higher
14        //
15        // If you are using Android Studio, and it is using Gradle's lower
16        // version, Use the plugin version 3.1.3 ~ 3.2.0 for Gradle 4.4 ~ 4.10
17        classpath 'com.android.tools.build:gradle:3.3.0'
18    }
19}
20repositories {
21    google()
22    jcenter()
23}
24
25// Output: Shared library (.so) for Android
26apply plugin: 'com.android.library'
27
28android {
29    compileSdkVersion 25    // Android 7.0
30
31    // Target ABI
32    //  - This option controls target platform of module
33    //  - The platform might be limited by compiler's support
34    //    some can work with Clang(default), but some can work only with GCC...
35    //    if bad, both toolchains might not support it
36    splits {
37        abi {
38            enable true
39            // Specify platforms for Application
40            reset()
41            include  "arm64-v8a", "armeabi-v7a", "x86_64"
42        }
43    }
44
45    defaultConfig {
46        minSdkVersion 21    // Android 5.0+
47        targetSdkVersion 25 // Follow Compile SDK
48        versionCode 21      // Follow release count
49        versionName "5.3.0" // Follow Official version
50        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
51
52        externalNativeBuild {
53            cmake {
54                arguments "-DANDROID_STL=c++_shared"    // Specify Android STL
55                arguments "-DBUILD_SHARED_LIBS=true"    // Build shared object
56                arguments "-DFMT_TEST=false"            // Skip test
57                arguments "-DFMT_DOC=false"             // Skip document
58                cppFlags  "-std=c++17"
59            }
60        }
61        println("Gradle CMake Plugin: ")
62        println(externalNativeBuild.cmake.cppFlags)
63        println(externalNativeBuild.cmake.arguments)
64    }
65
66    // External Native build
67    //  - Use existing CMakeList.txt
68    //  - Give path to CMake. This gradle file should be
69    //    neighbor of the top level cmake
70    externalNativeBuild {
71        cmake {
72            path "../CMakeLists.txt"
73            // buildStagingDirectory "./build"  // Custom path for cmake output
74        }
75        //println(cmake.path)
76    }
77
78    sourceSets{
79        // Android Manifest for Gradle
80        main {
81            manifest.srcFile 'AndroidManifest.xml'
82        }
83    }
84}
85
86assemble.doLast
87{
88    // Instead of `ninja install`, Gradle will deploy the files.
89    // We are doing this since FMT is dependent to the ANDROID_STL after build
90    copy {
91        from 'build/intermediates/cmake'
92        into '../libs'
93    }
94    // Copy debug binaries
95    copy {
96        from '../libs/debug/obj'
97        into '../libs/debug'
98    }
99    // Copy Release binaries
100    copy {
101        from '../libs/release/obj'
102        into '../libs/release'
103    }
104    // Remove empty directory
105    delete '../libs/debug/obj'
106    delete '../libs/release/obj'
107}
108