build.gradle.kts 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. //
  2. // Copyright (c) 2008-2020 the Urho3D project.
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to deal
  6. // in the Software without restriction, including without limitation the rights
  7. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. // copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. // THE SOFTWARE.
  21. //
  22. import org.gradle.internal.io.NullOutputStream
  23. import org.gradle.internal.os.OperatingSystem
  24. plugins {
  25. id("com.android.library")
  26. id("com.jfrog.bintray")
  27. kotlin("android")
  28. kotlin("android.extensions")
  29. `maven-publish`
  30. }
  31. val kotlinVersion: String by ext
  32. val ndkSideBySideVersion: String by ext
  33. val cmakeVersion: String by ext
  34. val buildStagingDir: String by ext
  35. android {
  36. ndkVersion = ndkSideBySideVersion
  37. compileSdkVersion(30)
  38. defaultConfig {
  39. minSdkVersion(18)
  40. targetSdkVersion(30)
  41. versionCode = 1
  42. versionName = project.version.toString()
  43. testInstrumentationRunner = "android.support.test.runner.AndroidJUnitRunner"
  44. externalNativeBuild {
  45. cmake {
  46. arguments.apply {
  47. System.getenv("ANDROID_CCACHE")?.let { add("-D ANDROID_CCACHE=$it") }
  48. // Pass along matching env-vars as CMake build options
  49. addAll(project.file("../../script/.build-options")
  50. .readLines()
  51. .mapNotNull { variable -> System.getenv(variable)?.let { "-D $variable=$it" } }
  52. )
  53. }
  54. targets.add("Urho3D")
  55. }
  56. }
  57. splits {
  58. abi {
  59. isEnable = project.hasProperty("ANDROID_ABI")
  60. reset()
  61. include(
  62. *(project.findProperty("ANDROID_ABI") as String? ?: "")
  63. .split(',')
  64. .toTypedArray()
  65. )
  66. }
  67. }
  68. }
  69. buildTypes {
  70. named("release") {
  71. isMinifyEnabled = false
  72. proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
  73. }
  74. }
  75. externalNativeBuild {
  76. cmake {
  77. version = cmakeVersion
  78. path = project.file("../../CMakeLists.txt")
  79. setBuildStagingDirectory(buildStagingDir)
  80. }
  81. }
  82. sourceSets {
  83. named("main") {
  84. java.srcDir("../../Source/ThirdParty/SDL/android-project/app/src/main/java")
  85. }
  86. }
  87. }
  88. dependencies {
  89. implementation(fileTree(mapOf("dir" to "libs", "include" to listOf("*.jar", "*.aar"))))
  90. implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlinVersion")
  91. implementation("com.getkeepsafe.relinker:relinker:1.4.1")
  92. testImplementation("junit:junit:4.13.1")
  93. androidTestImplementation("androidx.test:runner:1.3.0")
  94. androidTestImplementation("androidx.test.espresso:espresso-core:3.3.0")
  95. }
  96. android.libraryVariants.whenObjectAdded {
  97. val config = name
  98. packageLibraryProvider.get().apply {
  99. // Customize bundle task to also zip the Urho3D headers and libraries
  100. File(android.externalNativeBuild.cmake.buildStagingDirectory, "cmake/$config").list()?.forEach { abi ->
  101. listOf("include", "lib").forEach {
  102. from(File(android.externalNativeBuild.cmake.buildStagingDirectory, "cmake/$config/$abi/$it")) {
  103. into("urho3d/$config/$abi/$it")
  104. }
  105. }
  106. }
  107. }
  108. }
  109. tasks {
  110. register<Delete>("cleanAll") {
  111. dependsOn("clean")
  112. delete = setOf(android.externalNativeBuild.cmake.buildStagingDirectory)
  113. }
  114. register<Jar>("sourcesJar") {
  115. archiveClassifier.set("sources")
  116. from(android.sourceSets.getByName("main").java.srcDirs)
  117. }
  118. register<Zip>("documentationZip") {
  119. archiveClassifier.set("documentation")
  120. dependsOn("makeDoc")
  121. }
  122. register<Exec>("makeDoc") {
  123. // Ignore the exit status on Windows host system because Doxygen may not return exit status correctly on Windows
  124. isIgnoreExitValue = OperatingSystem.current().isWindows
  125. standardOutput = NullOutputStream.INSTANCE
  126. args("--build", ".", "--target", "doc")
  127. dependsOn("makeDocConfigurer")
  128. }
  129. register<Task>("makeDocConfigurer") {
  130. dependsOn("generateJsonModelRelease")
  131. doLast {
  132. val abi = File(android.externalNativeBuild.cmake.buildStagingDirectory, "cmake/release").list()!!.first()
  133. val buildTree = File(android.externalNativeBuild.cmake.buildStagingDirectory, "cmake/release/$abi")
  134. named<Exec>("makeDoc") {
  135. // This is a hack - expect the first line to contain the path to the CMake executable
  136. executable = File(buildTree, "build_command.txt").readLines().first().split(":").last().trim()
  137. workingDir = buildTree
  138. }
  139. named<Zip>("documentationZip") {
  140. from(File(buildTree, "Docs/html")) {
  141. into("docs")
  142. }
  143. }
  144. }
  145. }
  146. }
  147. publishing {
  148. publications {
  149. android.buildTypes.forEach {
  150. val config = it.name
  151. register<MavenPublication>("Urho${config.capitalize()}") {
  152. configure(config)
  153. }
  154. }
  155. }
  156. repositories {
  157. maven {
  158. name = "GitHubPackages"
  159. url = uri("https://maven.pkg.github.com/urho3d/Urho3D")
  160. credentials {
  161. username = System.getenv("GITHUB_ACTOR")
  162. password = System.getenv("GITHUB_TOKEN")
  163. }
  164. }
  165. }
  166. }
  167. bintray {
  168. user = System.getenv("BINTRAY_USER")
  169. key = System.getenv("BINTRAY_KEY")
  170. publish = true
  171. override = true
  172. setPublications("UrhoRelease", "UrhoDebug")
  173. pkg.apply {
  174. repo = "maven"
  175. name = project.name
  176. setLicenses("MIT")
  177. vcsUrl = "https://github.com/urho3d/Urho3D.git"
  178. userOrg = "urho3d"
  179. setLabels("android", "game-development", "game-engine", "open-source", "urho3d")
  180. websiteUrl = "https://urho3d.io/"
  181. issueTrackerUrl = "https://github.com/urho3d/Urho3D/issues"
  182. githubRepo = "urho3d/Urho3D"
  183. publicDownloadNumbers = true
  184. desc = project.description
  185. version.apply {
  186. name = project.version.toString()
  187. desc = project.description
  188. }
  189. }
  190. }
  191. fun MavenPublication.configure(config: String) {
  192. val libType = System.getenv("URHO3D_LIB_TYPE")?.toLowerCase() ?: "static"
  193. groupId = project.group.toString()
  194. artifactId = "${project.name}-$libType${if (config == "debug") "-debug" else ""}"
  195. afterEvaluate {
  196. from(components[config])
  197. }
  198. artifact(tasks["sourcesJar"])
  199. artifact(tasks["documentationZip"])
  200. pom {
  201. inceptionYear.set("2008")
  202. licenses {
  203. license {
  204. name.set("MIT License")
  205. url.set("https://github.com/urho3d/Urho3D/blob/master/LICENSE")
  206. }
  207. }
  208. developers {
  209. developer {
  210. name.set("Urho3D contributors")
  211. url.set("https://github.com/urho3d/Urho3D/graphs/contributors")
  212. }
  213. }
  214. scm {
  215. url.set("https://github.com/urho3d/Urho3D.git")
  216. connection.set("scm:git:ssh://[email protected]:urho3d/Urho3D.git")
  217. developerConnection.set("scm:git:ssh://[email protected]:urho3d/Urho3D.git")
  218. }
  219. withXml {
  220. asNode().apply {
  221. appendNode("name", "Urho3D")
  222. appendNode("description", project.description)
  223. appendNode("url", "https://urho3d.io/")
  224. }
  225. }
  226. }
  227. }