build.gradle.kts 8.0 KB

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