build.gradle 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. import java.nio.charset.StandardCharsets
  2. plugins {
  3. id 'com.android.application'
  4. }
  5. android {
  6. namespace "com.nonvioce.farm"
  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_POLICY_VERSION_MINIMUM=3.5", "-DCMAKE_DISABLE_PRECOMPILE_HEADERS=ON", "-DCMAKE_BUILD_TYPE=RelWithDebInfo"
  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. // 移除全局abiFilters,使用productFlavors为每个架构创建单独的构建
  27. ndk {
  28. //noinspection ChromeOsAbiSupport
  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. // 遍历lua-modules目录,寻找包含Android.mk或CMakeLists.mk的目录
  56. def luaModulesDir = file("src/main/cpp/lua-modules/")
  57. if (luaModulesDir.exists() && luaModulesDir.isDirectory()) {
  58. luaModulesDir.eachFileRecurse { file ->
  59. if (file.isDirectory()) {
  60. def androidMk = file("${file.path}/Android.mk")
  61. def cmakeLists = file("${file.path}/CMakeLists.mk")
  62. if (androidMk.exists() || cmakeLists.exists()) {
  63. def logger = project.getLogger()
  64. logger.lifecycle("3rd-party module: ${file.path}")
  65. def javainfo = file("${file.path}/java.txt")
  66. if (javainfo.exists()) {
  67. def fstream = new FileInputStream(javainfo)
  68. def infile = new BufferedReader(new InputStreamReader(fstream))
  69. def javapath = infile.readLine().replace("\\", "/")
  70. def mpath = null
  71. if (javapath[0] != '/') {
  72. mpath = "${file.path}/${javapath}"
  73. } else {
  74. mpath = "${file.path}${javapath}"
  75. }
  76. modules << mpath
  77. logger.lifecycle("Registered path ${mpath}")
  78. infile.close()
  79. }
  80. }
  81. }
  82. }
  83. }
  84. return modules
  85. }
  86. buildTypes {
  87. release {
  88. minifyEnabled false
  89. proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
  90. }
  91. }
  92. buildFeatures {
  93. prefab true
  94. }
  95. flavorDimensions = ['mode', 'recording', 'architecture']
  96. productFlavors {
  97. normal {
  98. dimension 'mode'
  99. }
  100. embed {
  101. dimension 'mode'
  102. }
  103. record {
  104. dimension 'recording'
  105. }
  106. noRecord {
  107. dimension 'recording'
  108. }
  109. // 为每个架构创建单独的构建变体
  110. armeabiV7a {
  111. dimension 'architecture'
  112. ndk {
  113. abiFilters 'armeabi-v7a'
  114. }
  115. versionCode 101
  116. }
  117. arm64V8a {
  118. dimension 'architecture'
  119. ndk {
  120. abiFilters 'arm64-v8a'
  121. }
  122. versionCode 102
  123. }
  124. x86_64 {
  125. dimension 'architecture'
  126. ndk {
  127. abiFilters 'x86_64'
  128. }
  129. versionCode 103
  130. }
  131. }
  132. sourceSets {
  133. main {
  134. java {
  135. srcDir 'src/main/cpp/megasource/libs/SDL3/android-project/app/src/main/java'
  136. srcDir 'src/main/java'
  137. srcDir 'src/main/cpp/love/src/libraries/luahttps/src/android/java'
  138. srcDirs += retrieveAll3pModules()
  139. }
  140. }
  141. normal {
  142. java {
  143. srcDir 'src/normal/java'
  144. }
  145. }
  146. }
  147. compileOptions {
  148. sourceCompatibility JavaVersion.VERSION_1_8
  149. targetCompatibility JavaVersion.VERSION_1_8
  150. }
  151. buildFeatures {
  152. viewBinding true
  153. }
  154. externalNativeBuild {
  155. cmake {
  156. path file('src/main/cpp/CMakeLists.txt')
  157. // '+' notation apparently has been supported long time ago
  158. // https://issuetracker.google.com/issues/110693527#comment22
  159. // We require CMake 3.21 because r23 has important fixes
  160. // that's only fixed if CMake 3.21 is used.
  161. // https://github.com/android/ndk/issues/463
  162. version '3.21.0+'
  163. }
  164. }
  165. packagingOptions {
  166. jniLibs {
  167. excludes += [
  168. 'lib/armeabi-v7a/libOpenSLES.so',
  169. 'lib/arm64-v8a/libOpenSLES.so',
  170. 'lib/x86/libOpenSLES.so',
  171. 'lib/x86_64/libOpenSLES.so'
  172. ]
  173. }
  174. }
  175. }
  176. dependencies {
  177. implementation 'androidx.appcompat:appcompat:1.7.0'
  178. implementation 'com.google.android.material:material:1.12.0'
  179. implementation 'androidx.constraintlayout:constraintlayout:2.2.0'
  180. implementation 'androidx.navigation:navigation-fragment:2.8.5'
  181. implementation 'androidx.navigation:navigation-ui:2.8.5'
  182. implementation 'androidx.recyclerview:recyclerview:1.3.2'
  183. implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'
  184. implementation 'com.google.oboe:oboe:1.9.3'
  185. }
  186. // We don't even use Kotlin. Why we have to care about it?
  187. configurations.implementation {
  188. exclude group: 'org.jetbrains.kotlin', module: 'kotlin-stdlib-jdk8'
  189. }