build.gradle 7.9 KB

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