build.gradle 6.1 KB

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