build.gradle.kts 7.3 KB

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