build.gradle 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. import java.nio.charset.StandardCharsets
  2. plugins {
  3. id 'com.android.application'
  4. }
  5. android {
  6. namespace "org.love2d.android"
  7. ndkVersion "26.1.10909125"
  8. defaultConfig {
  9. applicationId project.properties["app.application_id"]
  10. versionCode project.properties["app.version_code"].toInteger()
  11. versionName project.properties["app.version_name"]
  12. minSdk 23
  13. compileSdk 34
  14. targetSdk 34
  15. externalNativeBuild {
  16. cmake {
  17. arguments "-DANDROID_STL=c++_shared"
  18. // https://issuetracker.google.com/issues/274493986
  19. // Transitive shared library that's added through `add_dependencies` is not taken into
  20. // account. This result in liboboe.so and libluajit.so not get included into the final
  21. // APK. "love" target depends on LuaJIT, and OpenAL that depends on oboe::oboe. So,
  22. // add "OpenAL" and "love" target.
  23. targets "love_android", "OpenAL", "love"
  24. }
  25. }
  26. def getAppName = {
  27. def nameArray = project.properties["app.name_byte_array"]
  28. def name = project.properties["app.name"]
  29. if (name != null && nameArray != null) {
  30. throw new Exception("Only define either `app.name` or `app.name_byte_array` in gradle.properties, but not both!")
  31. }
  32. if (name == null) {
  33. def nameArraySplit = nameArray.split(",")
  34. def nameBytes = new byte[nameArraySplit.length]
  35. def count = 0
  36. for (String s: nameArraySplit) {
  37. nameBytes[count++] = (byte) Integer.parseInt(s)
  38. }
  39. return new String(nameBytes, StandardCharsets.UTF_8)
  40. }
  41. return name
  42. }
  43. manifestPlaceholders = [
  44. NAME:getAppName(),
  45. ORIENTATION:project.properties["app.orientation"],
  46. ]
  47. }
  48. def retrieveAll3pModules = { ->
  49. def modules = []
  50. fileTree("src/main/cpp/lua-modules/").visit { FileVisitDetails details ->
  51. if (details.isDirectory()) {
  52. if (file(details.file.path + "/Android.mk").exists() ||
  53. file(details.file.path + "/CMakeLists.mk").exists()) {
  54. def logger = project.getLogger()
  55. logger.lifecycle("3rd-party module: " + details.file.path)
  56. def javainfo = file(details.file.path + "/java.txt")
  57. if (javainfo.exists()) {
  58. def fstream = new FileInputStream(javainfo)
  59. def infile = new BufferedReader(new InputStreamReader(fstream))
  60. def javapath = infile.readLine().replace("\\", "/")
  61. def mpath = null
  62. if (javapath[0] != '/') {
  63. mpath = details.file.path + "/" + javapath
  64. } else {
  65. mpath = details.file.path + javapath
  66. }
  67. modules << mpath
  68. logger.lifecycle("Registered path " + mpath)
  69. infile.close()
  70. }
  71. }
  72. }
  73. }
  74. return modules
  75. }
  76. buildTypes {
  77. release {
  78. minifyEnabled false
  79. proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
  80. }
  81. }
  82. buildFeatures {
  83. prefab true
  84. }
  85. flavorDimensions = ['mode', 'recording']
  86. productFlavors {
  87. normal {
  88. dimension 'mode'
  89. }
  90. embed {
  91. dimension 'mode'
  92. }
  93. record {
  94. dimension 'recording'
  95. }
  96. noRecord {
  97. dimension 'recording'
  98. }
  99. }
  100. sourceSets {
  101. main {
  102. java {
  103. srcDir 'src/main/cpp/megasource/libs/SDL2/android-project/app/src/main/java'
  104. srcDir 'src/main/java'
  105. srcDir 'src/main/cpp/love/src/libraries/luahttps/src/android/java'
  106. srcDirs += retrieveAll3pModules()
  107. }
  108. }
  109. normal {
  110. java {
  111. srcDir 'src/normal/java'
  112. }
  113. }
  114. }
  115. compileOptions {
  116. sourceCompatibility JavaVersion.VERSION_1_8
  117. targetCompatibility JavaVersion.VERSION_1_8
  118. }
  119. buildFeatures {
  120. viewBinding true
  121. }
  122. externalNativeBuild {
  123. cmake {
  124. path file('src/main/cpp/CMakeLists.txt')
  125. // '+' notation apparently has been supported long time ago
  126. // https://issuetracker.google.com/issues/110693527#comment22
  127. // We require CMake 3.21 because r23 has important fixes
  128. // that's only fixed if CMake 3.21 is used.
  129. // https://github.com/android/ndk/issues/463
  130. version '3.21.0+'
  131. }
  132. }
  133. packagingOptions {
  134. jniLibs {
  135. excludes += [
  136. 'lib/armeabi-v7a/libOpenSLES.so',
  137. 'lib/arm64-v8a/libOpenSLES.so',
  138. 'lib/x86/libOpenSLES.so',
  139. 'lib/x86_64/libOpenSLES.so'
  140. ]
  141. }
  142. }
  143. }
  144. dependencies {
  145. implementation 'androidx.appcompat:appcompat:1.6.1'
  146. implementation 'com.google.android.material:material:1.9.0'
  147. implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
  148. implementation 'androidx.navigation:navigation-fragment:2.7.3'
  149. implementation 'androidx.navigation:navigation-ui:2.7.3'
  150. implementation 'androidx.recyclerview:recyclerview:1.3.1'
  151. implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'
  152. implementation 'com.google.oboe:oboe:1.7.0'
  153. }
  154. // We don't even use Kotlin. Why we have to care about it?
  155. configurations.implementation {
  156. exclude group: 'org.jetbrains.kotlin', module: 'kotlin-stdlib-jdk8'
  157. }