build.gradle 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  1. // Gradle build config for Godot Engine's Android port.
  2. //
  3. // Do not remove/modify comments ending with BEGIN/END, they are used to inject
  4. // addon-specific configuration.
  5. buildscript {
  6. apply from: 'config.gradle'
  7. repositories {
  8. google()
  9. mavenCentral()
  10. gradlePluginPortal()
  11. maven { url "https://plugins.gradle.org/m2/" }
  12. maven { url "https://central.sonatype.com/repository/maven-snapshots/"}
  13. //CHUNK_BUILDSCRIPT_REPOSITORIES_BEGIN
  14. //CHUNK_BUILDSCRIPT_REPOSITORIES_END
  15. }
  16. dependencies {
  17. classpath "com.android.tools.build:gradle:$versions.androidGradlePlugin"
  18. classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$versions.kotlinVersion"
  19. //CHUNK_BUILDSCRIPT_DEPENDENCIES_BEGIN
  20. //CHUNK_BUILDSCRIPT_DEPENDENCIES_END
  21. }
  22. }
  23. plugins {
  24. id 'com.android.application'
  25. id 'org.jetbrains.kotlin.android'
  26. }
  27. apply from: 'config.gradle'
  28. allprojects {
  29. repositories {
  30. google()
  31. mavenCentral()
  32. gradlePluginPortal()
  33. maven { url "https://plugins.gradle.org/m2/" }
  34. maven { url "https://central.sonatype.com/repository/maven-snapshots/"}
  35. //CHUNK_ALLPROJECTS_REPOSITORIES_BEGIN
  36. //CHUNK_ALLPROJECTS_REPOSITORIES_END
  37. // Godot user plugins custom maven repos
  38. String[] mavenRepos = getGodotPluginsMavenRepos()
  39. if (mavenRepos != null && mavenRepos.size() > 0) {
  40. for (String repoUrl : mavenRepos) {
  41. maven {
  42. url repoUrl
  43. }
  44. }
  45. }
  46. }
  47. }
  48. configurations {
  49. // Initializes a placeholder for the devImplementation dependency configuration.
  50. devImplementation {}
  51. }
  52. dependencies {
  53. implementation "androidx.fragment:fragment:$versions.fragmentVersion"
  54. if (rootProject.findProject(":lib")) {
  55. implementation project(":lib")
  56. } else if (rootProject.findProject(":godot:lib")) {
  57. implementation project(":godot:lib")
  58. } else {
  59. // Custom build mode. In this scenario this project is the only one around and the Godot
  60. // library is available through the pre-generated godot-lib.*.aar android archive files.
  61. debugImplementation fileTree(dir: 'libs/debug', include: ['*.jar', '*.aar'])
  62. devImplementation fileTree(dir: 'libs/dev', include: ['*.jar', '*.aar'])
  63. releaseImplementation fileTree(dir: 'libs/release', include: ['*.jar', '*.aar'])
  64. }
  65. // Godot user plugins remote dependencies
  66. String[] remoteDeps = getGodotPluginsRemoteBinaries()
  67. if (remoteDeps != null && remoteDeps.size() > 0) {
  68. for (String dep : remoteDeps) {
  69. implementation dep
  70. }
  71. }
  72. // Godot user plugins local dependencies
  73. String[] pluginsBinaries = getGodotPluginsLocalBinaries()
  74. if (pluginsBinaries != null && pluginsBinaries.size() > 0) {
  75. implementation files(pluginsBinaries)
  76. }
  77. //CHUNK_DEPENDENCIES_BEGIN
  78. //CHUNK_DEPENDENCIES_END
  79. }
  80. android {
  81. compileSdkVersion versions.compileSdk
  82. buildToolsVersion versions.buildTools
  83. ndkVersion versions.ndkVersion
  84. compileOptions {
  85. sourceCompatibility versions.javaVersion
  86. targetCompatibility versions.javaVersion
  87. }
  88. kotlinOptions {
  89. jvmTarget = versions.javaVersion
  90. }
  91. assetPacks = [":assetPackInstallTime"]
  92. namespace = 'com.godot.game'
  93. defaultConfig {
  94. // The default ignore pattern for the 'assets' directory includes hidden files and directories which are used by Godot projects.
  95. aaptOptions {
  96. ignoreAssetsPattern "!.svn:!.git:!.gitignore:!.ds_store:!*.scc:<dir>_*:!CVS:!thumbs.db:!picasa.ini:!*~"
  97. }
  98. ndk {
  99. String[] export_abi_list = getExportEnabledABIs()
  100. abiFilters export_abi_list
  101. }
  102. manifestPlaceholders = [godotEditorVersion: getGodotEditorVersion()]
  103. // Feel free to modify the application id to your own.
  104. applicationId getExportPackageName()
  105. versionCode getExportVersionCode()
  106. versionName getExportVersionName()
  107. minSdkVersion getExportMinSdkVersion()
  108. targetSdkVersion getExportTargetSdkVersion()
  109. missingDimensionStrategy 'products', 'template'
  110. //CHUNK_ANDROID_DEFAULTCONFIG_BEGIN
  111. //CHUNK_ANDROID_DEFAULTCONFIG_END
  112. }
  113. lintOptions {
  114. abortOnError false
  115. disable 'MissingTranslation', 'UnusedResources'
  116. }
  117. ndkVersion versions.ndkVersion
  118. packagingOptions {
  119. exclude 'META-INF/LICENSE'
  120. exclude 'META-INF/NOTICE'
  121. // 'doNotStrip' is enabled for development within Android Studio
  122. if (shouldNotStrip()) {
  123. doNotStrip '**/*.so'
  124. }
  125. }
  126. signingConfigs {
  127. debug {
  128. if (hasCustomDebugKeystore()) {
  129. storeFile new File(getDebugKeystoreFile())
  130. storePassword getDebugKeystorePassword()
  131. keyAlias getDebugKeyAlias()
  132. keyPassword getDebugKeystorePassword()
  133. }
  134. }
  135. release {
  136. File keystoreFile = new File(getReleaseKeystoreFile())
  137. if (keystoreFile.isFile()) {
  138. storeFile keystoreFile
  139. storePassword getReleaseKeystorePassword()
  140. keyAlias getReleaseKeyAlias()
  141. keyPassword getReleaseKeystorePassword()
  142. }
  143. }
  144. }
  145. buildTypes {
  146. debug {
  147. // Signing and zip-aligning are skipped for prebuilt builds, but
  148. // performed for custom builds.
  149. zipAlignEnabled shouldZipAlign()
  150. if (shouldSign()) {
  151. signingConfig signingConfigs.debug
  152. } else {
  153. signingConfig null
  154. }
  155. }
  156. dev {
  157. initWith debug
  158. // Signing and zip-aligning are skipped for prebuilt builds, but
  159. // performed for custom builds.
  160. zipAlignEnabled shouldZipAlign()
  161. if (shouldSign()) {
  162. signingConfig signingConfigs.debug
  163. } else {
  164. signingConfig null
  165. }
  166. }
  167. release {
  168. // Signing and zip-aligning are skipped for prebuilt builds, but
  169. // performed for custom builds.
  170. zipAlignEnabled shouldZipAlign()
  171. if (shouldSign()) {
  172. signingConfig signingConfigs.release
  173. } else {
  174. signingConfig null
  175. }
  176. }
  177. }
  178. sourceSets {
  179. main {
  180. manifest.srcFile 'AndroidManifest.xml'
  181. java.srcDirs = [
  182. 'src'
  183. //DIR_SRC_BEGIN
  184. //DIR_SRC_END
  185. ]
  186. res.srcDirs = [
  187. 'res'
  188. //DIR_RES_BEGIN
  189. //DIR_RES_END
  190. ]
  191. aidl.srcDirs = [
  192. 'aidl'
  193. //DIR_AIDL_BEGIN
  194. //DIR_AIDL_END
  195. ]
  196. assets.srcDirs = [
  197. 'assets'
  198. //DIR_ASSETS_BEGIN
  199. //DIR_ASSETS_END
  200. ]
  201. }
  202. debug.jniLibs.srcDirs = [
  203. 'libs/debug'
  204. //DIR_JNI_DEBUG_BEGIN
  205. //DIR_JNI_DEBUG_END
  206. ]
  207. dev.jniLibs.srcDirs = [
  208. 'libs/dev'
  209. //DIR_JNI_DEV_BEGIN
  210. //DIR_JNI_DEV_END
  211. ]
  212. release.jniLibs.srcDirs = [
  213. 'libs/release'
  214. //DIR_JNI_RELEASE_BEGIN
  215. //DIR_JNI_RELEASE_END
  216. ]
  217. }
  218. applicationVariants.all { variant ->
  219. variant.outputs.all { output ->
  220. output.outputFileName = "android_${variant.name}.apk"
  221. }
  222. }
  223. }
  224. task copyAndRenameDebugApk(type: Copy) {
  225. from "$buildDir/outputs/apk/debug/android_debug.apk"
  226. into getExportPath()
  227. rename "android_debug.apk", getExportFilename()
  228. }
  229. task copyAndRenameDevApk(type: Copy) {
  230. from "$buildDir/outputs/apk/dev/android_dev.apk"
  231. into getExportPath()
  232. rename "android_dev.apk", getExportFilename()
  233. }
  234. task copyAndRenameReleaseApk(type: Copy) {
  235. from "$buildDir/outputs/apk/release/android_release.apk"
  236. into getExportPath()
  237. rename "android_release.apk", getExportFilename()
  238. }
  239. task copyAndRenameDebugAab(type: Copy) {
  240. from "$buildDir/outputs/bundle/debug/build-debug.aab"
  241. into getExportPath()
  242. rename "build-debug.aab", getExportFilename()
  243. }
  244. task copyAndRenameDevAab(type: Copy) {
  245. from "$buildDir/outputs/bundle/dev/build-dev.aab"
  246. into getExportPath()
  247. rename "build-dev.aab", getExportFilename()
  248. }
  249. task copyAndRenameReleaseAab(type: Copy) {
  250. from "$buildDir/outputs/bundle/release/build-release.aab"
  251. into getExportPath()
  252. rename "build-release.aab", getExportFilename()
  253. }
  254. /**
  255. * Used to validate the version of the Java SDK used for the Godot gradle builds.
  256. */
  257. task validateJavaVersion {
  258. if (JavaVersion.current() != versions.javaVersion) {
  259. throw new GradleException("Invalid Java version ${JavaVersion.current()}. Version ${versions.javaVersion} is the required Java version for Godot gradle builds.")
  260. }
  261. }
  262. /*
  263. When they're scheduled to run, the copy*AARToAppModule tasks generate dependencies for the 'app'
  264. module, so we're ensuring the ':app:preBuild' task is set to run after those tasks.
  265. */
  266. if (rootProject.tasks.findByPath("copyDebugAARToAppModule") != null) {
  267. preBuild.mustRunAfter(rootProject.tasks.named("copyDebugAARToAppModule"))
  268. }
  269. if (rootProject.tasks.findByPath("copyDevAARToAppModule") != null) {
  270. preBuild.mustRunAfter(rootProject.tasks.named("copyDevAARToAppModule"))
  271. }
  272. if (rootProject.tasks.findByPath("copyReleaseAARToAppModule") != null) {
  273. preBuild.mustRunAfter(rootProject.tasks.named("copyReleaseAARToAppModule"))
  274. }
  275. //CHUNK_GLOBAL_BEGIN
  276. //CHUNK_GLOBAL_END