build.gradle.kts 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. plugins {
  2. id("com.android.application")
  3. id("org.jetbrains.kotlin.android")
  4. kotlin("plugin.serialization") version "1.8.21"
  5. id("androidx.baselineprofile")
  6. }
  7. @Suppress("UnstableApiUsage")
  8. android {
  9. compileSdkVersion = "android-34"
  10. ndkVersion = "27.0.12077973"
  11. buildFeatures {
  12. viewBinding = true
  13. buildConfig = true
  14. }
  15. compileOptions {
  16. // Flag to enable support for the new language APIs
  17. isCoreLibraryDesugaringEnabled = true
  18. sourceCompatibility = JavaVersion.VERSION_17
  19. targetCompatibility = JavaVersion.VERSION_17
  20. }
  21. kotlinOptions {
  22. jvmTarget = "17"
  23. }
  24. lint {
  25. // This is important as it will run lint but not abort on error
  26. // Lint has some overly obnoxious "errors" that should really be warnings
  27. abortOnError = false
  28. //Uncomment disable lines for test builds...
  29. //disable "MissingTranslation"
  30. //disable "ExtraTranslation"
  31. }
  32. defaultConfig {
  33. applicationId = "org.dolphinemu.dolphinemu"
  34. minSdk = 21
  35. targetSdk = 34
  36. versionCode = getBuildVersionCode()
  37. versionName = getGitVersion()
  38. buildConfigField("String", "GIT_HASH", "\"${getGitHash()}\"")
  39. buildConfigField("String", "BRANCH", "\"${getBranch()}\"")
  40. testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
  41. }
  42. signingConfigs {
  43. create("release") {
  44. if (project.hasProperty("keystore")) {
  45. storeFile = file(project.property("keystore")!!)
  46. storePassword = project.property("storepass").toString()
  47. keyAlias = project.property("keyalias").toString()
  48. keyPassword = project.property("keypass").toString()
  49. }
  50. }
  51. }
  52. // Define build types, which are orthogonal to product flavors.
  53. buildTypes {
  54. // Signed by release key, allowing for upload to Play Store.
  55. release {
  56. if (project.hasProperty("keystore")) {
  57. signingConfig = signingConfigs.getByName("release")
  58. }
  59. resValue("string", "app_name_suffixed", "Dolphin Emulator")
  60. isMinifyEnabled = true
  61. isShrinkResources = true
  62. proguardFiles(
  63. getDefaultProguardFile("proguard-android.txt"),
  64. "proguard-rules.pro"
  65. )
  66. }
  67. // Signed by debug key disallowing distribution on Play Store.
  68. // Attaches "debug" suffix to version and package name, allowing installation alongside the release build.
  69. debug {
  70. resValue("string", "app_name_suffixed", "Dolphin Debug")
  71. applicationIdSuffix = ".debug"
  72. versionNameSuffix = "-debug"
  73. isJniDebuggable = true
  74. }
  75. }
  76. externalNativeBuild {
  77. cmake {
  78. path = file("../../../CMakeLists.txt")
  79. version = "3.22.1+"
  80. }
  81. }
  82. namespace = "org.dolphinemu.dolphinemu"
  83. defaultConfig {
  84. externalNativeBuild {
  85. cmake {
  86. arguments(
  87. "-DANDROID_STL=c++_static",
  88. "-DANDROID_SUPPORT_FLEXIBLE_PAGE_SIZES=ON",
  89. "-DCMAKE_BUILD_TYPE=RelWithDebInfo"
  90. // , "-DENABLE_GENERIC=ON"
  91. )
  92. abiFilters("arm64-v8a", "x86_64") //, "armeabi-v7a", "x86"
  93. // Uncomment the line below if you don't want to build the C++ unit tests
  94. //targets("main", "hook_impl", "main_hook", "gsl_alloc_hook", "file_redirect_hook")
  95. }
  96. }
  97. }
  98. packaging {
  99. jniLibs.useLegacyPackaging = true
  100. }
  101. }
  102. dependencies {
  103. baselineProfile(project(":benchmark"))
  104. coreLibraryDesugaring("com.android.tools:desugar_jdk_libs:2.0.4")
  105. implementation("androidx.core:core-ktx:1.13.0")
  106. implementation("androidx.appcompat:appcompat:1.6.1")
  107. implementation("androidx.cardview:cardview:1.0.0")
  108. implementation("androidx.recyclerview:recyclerview:1.3.2")
  109. implementation("androidx.constraintlayout:constraintlayout:2.1.4")
  110. implementation("androidx.fragment:fragment-ktx:1.6.2")
  111. implementation("androidx.slidingpanelayout:slidingpanelayout:1.2.0")
  112. implementation("com.google.android.material:material:1.11.0")
  113. implementation("androidx.core:core-splashscreen:1.0.1")
  114. implementation("androidx.preference:preference-ktx:1.2.1")
  115. implementation("androidx.profileinstaller:profileinstaller:1.3.1")
  116. // Kotlin extensions for lifecycle components
  117. implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:2.7.0")
  118. implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.7.0")
  119. // Android TV UI libraries.
  120. implementation("androidx.leanback:leanback:1.0.0")
  121. implementation("androidx.tvprovider:tvprovider:1.0.0")
  122. // For REST calls
  123. implementation("com.android.volley:volley:1.2.1")
  124. // For loading game covers from disk and GameTDB
  125. implementation("io.coil-kt:coil:2.6.0")
  126. // For loading custom GPU drivers
  127. implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.3")
  128. implementation("com.nononsenseapps:filepicker:4.2.1")
  129. }
  130. fun getGitVersion(): String {
  131. try {
  132. return ProcessBuilder("git", "describe", "--always", "--long")
  133. .directory(project.rootDir)
  134. .redirectOutput(ProcessBuilder.Redirect.PIPE)
  135. .redirectError(ProcessBuilder.Redirect.PIPE)
  136. .start().inputStream.bufferedReader().use { it.readText() }
  137. .trim()
  138. .replace(Regex("(-0)?-[^-]+$"), "")
  139. } catch (e: Exception) {
  140. logger.error("Cannot find git, defaulting to dummy version number")
  141. }
  142. return "0.0"
  143. }
  144. fun getBuildVersionCode(): Int {
  145. try {
  146. val commitCount = Integer.valueOf(
  147. ProcessBuilder("git", "rev-list", "--first-parent", "--count", "HEAD")
  148. .directory(project.rootDir)
  149. .redirectOutput(ProcessBuilder.Redirect.PIPE)
  150. .redirectError(ProcessBuilder.Redirect.PIPE)
  151. .start().inputStream.bufferedReader().use { it.readText() }
  152. .trim()
  153. )
  154. val isRelease = ProcessBuilder("git", "describe", "--exact-match", "HEAD")
  155. .directory(project.rootDir)
  156. .redirectOutput(ProcessBuilder.Redirect.PIPE)
  157. .redirectError(ProcessBuilder.Redirect.PIPE)
  158. .start()
  159. .waitFor() == 0
  160. return commitCount * 2 + (if (isRelease) 0 else 1)
  161. } catch (e: Exception) {
  162. logger.error("Cannot find git, defaulting to dummy version code")
  163. }
  164. return 1
  165. }
  166. fun getGitHash(): String {
  167. try {
  168. return ProcessBuilder("git", "rev-parse", "HEAD")
  169. .directory(project.rootDir)
  170. .redirectOutput(ProcessBuilder.Redirect.PIPE)
  171. .redirectError(ProcessBuilder.Redirect.PIPE)
  172. .start().inputStream.bufferedReader().use { it.readText() }
  173. .trim()
  174. } catch (e: Exception) {
  175. logger.error("Cannot find git, defaulting to dummy git hash")
  176. }
  177. return "0"
  178. }
  179. fun getBranch(): String {
  180. try {
  181. return ProcessBuilder("git", "rev-parse", "--abbrev-ref", "HEAD")
  182. .directory(project.rootDir)
  183. .redirectOutput(ProcessBuilder.Redirect.PIPE)
  184. .redirectError(ProcessBuilder.Redirect.PIPE)
  185. .start().inputStream.bufferedReader().use { it.readText() }
  186. .trim()
  187. } catch (e: Exception) {
  188. logger.error("Cannot find git, defaulting to dummy git hash")
  189. }
  190. return "master"
  191. }