build.gradle.kts 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. plugins {
  2. id("com.android.application")
  3. id("org.jetbrains.kotlin.android")
  4. id("kotlin-parcelize")
  5. kotlin("plugin.serialization") version "1.8.21"
  6. }
  7. /**
  8. * Use the number of seconds/10 since Jan 1 2016 as the versionCode.
  9. * This lets us upload a new build at most every 10 seconds for the
  10. * next 680 years.
  11. */
  12. val autoVersion = (((System.currentTimeMillis() / 1000) - 1451606400) / 10).toInt()
  13. @Suppress("UnstableApiUsage")
  14. android {
  15. namespace = "org.yuzu.yuzu_emu"
  16. compileSdkVersion = "android-33"
  17. ndkVersion = "25.2.9519653"
  18. buildFeatures {
  19. viewBinding = true
  20. }
  21. compileOptions {
  22. sourceCompatibility = JavaVersion.VERSION_17
  23. targetCompatibility = JavaVersion.VERSION_17
  24. }
  25. kotlinOptions {
  26. jvmTarget = "17"
  27. }
  28. lint {
  29. // This is important as it will run lint but not abort on error
  30. // Lint has some overly obnoxious "errors" that should really be warnings
  31. abortOnError = false
  32. //Uncomment disable lines for test builds...
  33. //disable 'MissingTranslation'bin
  34. //disable 'ExtraTranslation'
  35. }
  36. defaultConfig {
  37. // TODO If this is ever modified, change application_id in strings.xml
  38. applicationId = "org.yuzu.yuzu_emu"
  39. minSdk = 30
  40. targetSdk = 33
  41. versionName = getGitVersion()
  42. ndk {
  43. abiFilters += listOf("arm64-v8a")
  44. }
  45. buildConfigField("String", "GIT_HASH", "\"${getGitHash()}\"")
  46. buildConfigField("String", "BRANCH", "\"${getBranch()}\"")
  47. }
  48. // Define build types, which are orthogonal to product flavors.
  49. buildTypes {
  50. // Signed by release key, allowing for upload to Play Store.
  51. release {
  52. signingConfig = signingConfigs.getByName("debug")
  53. isMinifyEnabled = true
  54. isDebuggable = false
  55. proguardFiles(
  56. getDefaultProguardFile("proguard-android.txt"),
  57. "proguard-rules.pro"
  58. )
  59. }
  60. register("relWithVersionCode") {
  61. signingConfig = signingConfigs.getByName("debug")
  62. isMinifyEnabled = true
  63. isDebuggable = false
  64. proguardFiles(
  65. getDefaultProguardFile("proguard-android.txt"),
  66. "proguard-rules.pro"
  67. )
  68. }
  69. // builds a release build that doesn't need signing
  70. // Attaches 'debug' suffix to version and package name, allowing installation alongside the release build.
  71. register("relWithDebInfo") {
  72. signingConfig = signingConfigs.getByName("debug")
  73. isMinifyEnabled = true
  74. isDebuggable = true
  75. proguardFiles(
  76. getDefaultProguardFile("proguard-android.txt"),
  77. "proguard-rules.pro"
  78. )
  79. versionNameSuffix = "-debug"
  80. isJniDebuggable = true
  81. }
  82. // Signed by debug key disallowing distribution on Play Store.
  83. // Attaches 'debug' suffix to version and package name, allowing installation alongside the release build.
  84. debug {
  85. isDebuggable = true
  86. isJniDebuggable = true
  87. versionNameSuffix = "-debug"
  88. }
  89. }
  90. flavorDimensions.add("version")
  91. productFlavors {
  92. create("mainline") {
  93. dimension = "version"
  94. buildConfigField("Boolean", "PREMIUM", "false")
  95. }
  96. create("ea") {
  97. dimension = "version"
  98. buildConfigField("Boolean", "PREMIUM", "true")
  99. applicationIdSuffix = ".ea"
  100. }
  101. }
  102. externalNativeBuild {
  103. cmake {
  104. version = "3.22.1"
  105. path = file("../../../CMakeLists.txt")
  106. }
  107. }
  108. defaultConfig {
  109. externalNativeBuild {
  110. cmake {
  111. arguments(
  112. "-DENABLE_QT=0", // Don't use QT
  113. "-DENABLE_SDL2=0", // Don't use SDL
  114. "-DENABLE_WEB_SERVICE=0", // Don't use telemetry
  115. "-DBUNDLE_SPEEX=ON",
  116. "-DANDROID_ARM_NEON=true", // cryptopp requires Neon to work
  117. "-DYUZU_USE_BUNDLED_VCPKG=ON",
  118. "-DYUZU_USE_BUNDLED_FFMPEG=ON",
  119. "-DYUZU_ENABLE_LTO=ON"
  120. )
  121. abiFilters("arm64-v8a", "x86_64")
  122. }
  123. }
  124. }
  125. }
  126. dependencies {
  127. implementation("androidx.core:core-ktx:1.10.1")
  128. implementation("androidx.appcompat:appcompat:1.6.1")
  129. implementation("androidx.recyclerview:recyclerview:1.3.0")
  130. implementation("androidx.constraintlayout:constraintlayout:2.1.4")
  131. implementation("androidx.fragment:fragment-ktx:1.5.7")
  132. implementation("androidx.documentfile:documentfile:1.0.1")
  133. implementation("com.google.android.material:material:1.9.0")
  134. implementation("androidx.preference:preference:1.2.0")
  135. implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:2.6.1")
  136. implementation("io.coil-kt:coil:2.2.2")
  137. implementation("androidx.core:core-splashscreen:1.0.1")
  138. implementation("androidx.window:window:1.0.0")
  139. implementation("org.ini4j:ini4j:0.5.4")
  140. implementation("androidx.constraintlayout:constraintlayout:2.1.4")
  141. implementation("androidx.swiperefreshlayout:swiperefreshlayout:1.1.0")
  142. implementation("androidx.navigation:navigation-fragment-ktx:2.5.3")
  143. implementation("androidx.navigation:navigation-ui-ktx:2.5.3")
  144. implementation("info.debatty:java-string-similarity:2.0.0")
  145. implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.5.0")
  146. }
  147. fun getGitVersion(): String {
  148. var versionName = "0.0"
  149. try {
  150. versionName = ProcessBuilder("git", "describe", "--always", "--long")
  151. .directory(project.rootDir)
  152. .redirectOutput(ProcessBuilder.Redirect.PIPE)
  153. .redirectError(ProcessBuilder.Redirect.PIPE)
  154. .start().inputStream.bufferedReader().use { it.readText() }
  155. .trim()
  156. .replace(Regex("(-0)?-[^-]+$"), "")
  157. } catch (e: Exception) {
  158. logger.error("Cannot find git, defaulting to dummy version number")
  159. }
  160. if (System.getenv("GITHUB_ACTIONS") != null) {
  161. val gitTag = System.getenv("GIT_TAG_NAME")
  162. versionName = gitTag ?: versionName
  163. }
  164. return versionName
  165. }
  166. fun getGitHash(): String {
  167. try {
  168. val processBuilder = ProcessBuilder("git", "rev-parse", "--short", "HEAD")
  169. processBuilder.directory(project.rootDir)
  170. val process = processBuilder.start()
  171. val inputStream = process.inputStream
  172. val errorStream = process.errorStream
  173. process.waitFor()
  174. return if (process.exitValue() == 0) {
  175. inputStream.bufferedReader()
  176. .use { it.readText().trim() } // return the value of gitHash
  177. } else {
  178. val errorMessage = errorStream.bufferedReader().use { it.readText().trim() }
  179. logger.error("Error running git command: $errorMessage")
  180. "dummy-hash" // return a dummy hash value in case of an error
  181. }
  182. } catch (e: Exception) {
  183. logger.error("$e: Cannot find git, defaulting to dummy build hash")
  184. return "dummy-hash" // return a dummy hash value in case of an error
  185. }
  186. }
  187. fun getBranch(): String {
  188. try {
  189. val processBuilder = ProcessBuilder("git", "rev-parse", "--abbrev-ref", "HEAD")
  190. processBuilder.directory(project.rootDir)
  191. val process = processBuilder.start()
  192. val inputStream = process.inputStream
  193. val errorStream = process.errorStream
  194. process.waitFor()
  195. return if (process.exitValue() == 0) {
  196. inputStream.bufferedReader()
  197. .use { it.readText().trim() } // return the value of gitHash
  198. } else {
  199. val errorMessage = errorStream.bufferedReader().use { it.readText().trim() }
  200. logger.error("Error running git command: $errorMessage")
  201. "dummy-hash" // return a dummy hash value in case of an error
  202. }
  203. } catch (e: Exception) {
  204. logger.error("$e: Cannot find git, defaulting to dummy build hash")
  205. return "dummy-hash" // return a dummy hash value in case of an error
  206. }
  207. }