build.gradle 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. import java.nio.file.Paths
  2. // General gradle arguments for root project
  3. buildscript {
  4. repositories {
  5. google()
  6. jcenter()
  7. }
  8. dependencies {
  9. //
  10. // https://developer.android.com/studio/releases/gradle-plugin#updating-gradle
  11. //
  12. // Notice that 4.0.0 here is the version of [Android Gradle Plugin]
  13. // Accroding to URL above you will need Gradle 6.1 or higher
  14. //
  15. classpath "com.android.tools.build:gradle:4.1.1"
  16. }
  17. }
  18. repositories {
  19. google()
  20. jcenter()
  21. }
  22. // Project's root where CMakeLists.txt exists: rootDir/support/.cxx -> rootDir
  23. def rootDir = Paths.get(project.buildDir.getParent()).getParent()
  24. println("rootDir: ${rootDir}")
  25. // Output: Shared library (.so) for Android
  26. apply plugin: "com.android.library"
  27. android {
  28. compileSdkVersion 25 // Android 7.0
  29. // Target ABI
  30. // - This option controls target platform of module
  31. // - The platform might be limited by compiler's support
  32. // some can work with Clang(default), but some can work only with GCC...
  33. // if bad, both toolchains might not support it
  34. splits {
  35. abi {
  36. enable true
  37. // Specify platforms for Application
  38. reset()
  39. include "arm64-v8a", "armeabi-v7a", "x86_64"
  40. }
  41. }
  42. ndkVersion "21.3.6528147" // ANDROID_NDK_HOME is deprecated. Be explicit
  43. defaultConfig {
  44. minSdkVersion 21 // Android 5.0+
  45. targetSdkVersion 25 // Follow Compile SDK
  46. versionCode 34 // Follow release count
  47. versionName "7.1.2" // Follow Official version
  48. externalNativeBuild {
  49. cmake {
  50. arguments "-DANDROID_STL=c++_shared" // Specify Android STL
  51. arguments "-DBUILD_SHARED_LIBS=true" // Build shared object
  52. arguments "-DFMT_TEST=false" // Skip test
  53. arguments "-DFMT_DOC=false" // Skip document
  54. cppFlags "-std=c++17"
  55. targets "fmt"
  56. }
  57. }
  58. println(externalNativeBuild.cmake.cppFlags)
  59. println(externalNativeBuild.cmake.arguments)
  60. }
  61. // External Native build
  62. // - Use existing CMakeList.txt
  63. // - Give path to CMake. This gradle file should be
  64. // neighbor of the top level cmake
  65. externalNativeBuild {
  66. cmake {
  67. version "3.10.0+"
  68. path "${rootDir}/CMakeLists.txt"
  69. // buildStagingDirectory "./build" // Custom path for cmake output
  70. }
  71. }
  72. sourceSets{
  73. // Android Manifest for Gradle
  74. main {
  75. manifest.srcFile "AndroidManifest.xml"
  76. }
  77. }
  78. // https://developer.android.com/studio/build/native-dependencies#build_system_configuration
  79. buildFeatures {
  80. prefab true
  81. prefabPublishing true
  82. }
  83. prefab {
  84. fmt {
  85. headers "${rootDir}/include"
  86. }
  87. }
  88. }
  89. assemble.doLast
  90. {
  91. // Instead of `ninja install`, Gradle will deploy the files.
  92. // We are doing this since FMT is dependent to the ANDROID_STL after build
  93. copy {
  94. from "build/intermediates/cmake"
  95. into "${rootDir}/libs"
  96. }
  97. // Copy debug binaries
  98. copy {
  99. from "${rootDir}/libs/debug/obj"
  100. into "${rootDir}/libs/debug"
  101. }
  102. // Copy Release binaries
  103. copy {
  104. from "${rootDir}/libs/release/obj"
  105. into "${rootDir}/libs/release"
  106. }
  107. // Remove empty directory
  108. delete "${rootDir}/libs/debug/obj"
  109. delete "${rootDir}/libs/release/obj"
  110. // Copy AAR files. Notice that the aar is named after the folder of this script.
  111. copy {
  112. from "build/outputs/aar/support-release.aar"
  113. into "${rootDir}/libs"
  114. rename "support-release.aar", "fmt-release.aar"
  115. }
  116. copy {
  117. from "build/outputs/aar/support-debug.aar"
  118. into "${rootDir}/libs"
  119. rename "support-debug.aar", "fmt-debug.aar"
  120. }
  121. }