diff options
Diffstat (limited to 'src/android/app/build.gradle.kts')
| -rw-r--r-- | src/android/app/build.gradle.kts | 98 |
1 files changed, 37 insertions, 61 deletions
diff --git a/src/android/app/build.gradle.kts b/src/android/app/build.gradle.kts index 53aafa08c..188ef9469 100644 --- a/src/android/app/build.gradle.kts +++ b/src/android/app/build.gradle.kts | |||
| @@ -82,8 +82,8 @@ android { | |||
| 82 | } | 82 | } |
| 83 | 83 | ||
| 84 | val keystoreFile = System.getenv("ANDROID_KEYSTORE_FILE") | 84 | val keystoreFile = System.getenv("ANDROID_KEYSTORE_FILE") |
| 85 | if (keystoreFile != null) { | 85 | signingConfigs { |
| 86 | signingConfigs { | 86 | if (keystoreFile != null) { |
| 87 | create("release") { | 87 | create("release") { |
| 88 | storeFile = file(keystoreFile) | 88 | storeFile = file(keystoreFile) |
| 89 | storePassword = System.getenv("ANDROID_KEYSTORE_PASS") | 89 | storePassword = System.getenv("ANDROID_KEYSTORE_PASS") |
| @@ -91,6 +91,12 @@ android { | |||
| 91 | keyPassword = System.getenv("ANDROID_KEYSTORE_PASS") | 91 | keyPassword = System.getenv("ANDROID_KEYSTORE_PASS") |
| 92 | } | 92 | } |
| 93 | } | 93 | } |
| 94 | create("default") { | ||
| 95 | storeFile = file("$projectDir/debug.keystore") | ||
| 96 | storePassword = "android" | ||
| 97 | keyAlias = "androiddebugkey" | ||
| 98 | keyPassword = "android" | ||
| 99 | } | ||
| 94 | } | 100 | } |
| 95 | 101 | ||
| 96 | // Define build types, which are orthogonal to product flavors. | 102 | // Define build types, which are orthogonal to product flavors. |
| @@ -101,7 +107,7 @@ android { | |||
| 101 | signingConfig = if (keystoreFile != null) { | 107 | signingConfig = if (keystoreFile != null) { |
| 102 | signingConfigs.getByName("release") | 108 | signingConfigs.getByName("release") |
| 103 | } else { | 109 | } else { |
| 104 | signingConfigs.getByName("debug") | 110 | signingConfigs.getByName("default") |
| 105 | } | 111 | } |
| 106 | 112 | ||
| 107 | resValue("string", "app_name_suffixed", "yuzu") | 113 | resValue("string", "app_name_suffixed", "yuzu") |
| @@ -118,7 +124,7 @@ android { | |||
| 118 | register("relWithDebInfo") { | 124 | register("relWithDebInfo") { |
| 119 | isDefault = true | 125 | isDefault = true |
| 120 | resValue("string", "app_name_suffixed", "yuzu Debug Release") | 126 | resValue("string", "app_name_suffixed", "yuzu Debug Release") |
| 121 | signingConfig = signingConfigs.getByName("debug") | 127 | signingConfig = signingConfigs.getByName("default") |
| 122 | isMinifyEnabled = true | 128 | isMinifyEnabled = true |
| 123 | isDebuggable = true | 129 | isDebuggable = true |
| 124 | proguardFiles( | 130 | proguardFiles( |
| @@ -133,6 +139,7 @@ android { | |||
| 133 | // Signed by debug key disallowing distribution on Play Store. | 139 | // Signed by debug key disallowing distribution on Play Store. |
| 134 | // Attaches 'debug' suffix to version and package name, allowing installation alongside the release build. | 140 | // Attaches 'debug' suffix to version and package name, allowing installation alongside the release build. |
| 135 | debug { | 141 | debug { |
| 142 | signingConfig = signingConfigs.getByName("default") | ||
| 136 | resValue("string", "app_name_suffixed", "yuzu Debug") | 143 | resValue("string", "app_name_suffixed", "yuzu Debug") |
| 137 | isDebuggable = true | 144 | isDebuggable = true |
| 138 | isJniDebuggable = true | 145 | isJniDebuggable = true |
| @@ -188,8 +195,15 @@ tasks.create<Delete>("ktlintReset") { | |||
| 188 | delete(File(buildDir.path + File.separator + "intermediates/ktLint")) | 195 | delete(File(buildDir.path + File.separator + "intermediates/ktLint")) |
| 189 | } | 196 | } |
| 190 | 197 | ||
| 198 | val showFormatHelp = { | ||
| 199 | logger.lifecycle( | ||
| 200 | "If this check fails, please try running \"gradlew ktlintFormat\" for automatic " + | ||
| 201 | "codestyle fixes" | ||
| 202 | ) | ||
| 203 | } | ||
| 204 | tasks.getByPath("ktlintKotlinScriptCheck").doFirst { showFormatHelp.invoke() } | ||
| 205 | tasks.getByPath("ktlintMainSourceSetCheck").doFirst { showFormatHelp.invoke() } | ||
| 191 | tasks.getByPath("loadKtlintReporters").dependsOn("ktlintReset") | 206 | tasks.getByPath("loadKtlintReporters").dependsOn("ktlintReset") |
| 192 | tasks.getByPath("preBuild").dependsOn("ktlintCheck") | ||
| 193 | 207 | ||
| 194 | ktlint { | 208 | ktlint { |
| 195 | version.set("0.47.1") | 209 | version.set("0.47.1") |
| @@ -228,71 +242,33 @@ dependencies { | |||
| 228 | implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.5.0") | 242 | implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.5.0") |
| 229 | } | 243 | } |
| 230 | 244 | ||
| 231 | fun getGitVersion(): String { | 245 | fun runGitCommand(command: List<String>): String { |
| 232 | var versionName = "0.0" | 246 | return try { |
| 233 | 247 | ProcessBuilder(command) | |
| 234 | try { | ||
| 235 | versionName = ProcessBuilder("git", "describe", "--always", "--long") | ||
| 236 | .directory(project.rootDir) | 248 | .directory(project.rootDir) |
| 237 | .redirectOutput(ProcessBuilder.Redirect.PIPE) | 249 | .redirectOutput(ProcessBuilder.Redirect.PIPE) |
| 238 | .redirectError(ProcessBuilder.Redirect.PIPE) | 250 | .redirectError(ProcessBuilder.Redirect.PIPE) |
| 239 | .start().inputStream.bufferedReader().use { it.readText() } | 251 | .start().inputStream.bufferedReader().use { it.readText() } |
| 240 | .trim() | 252 | .trim() |
| 241 | .replace(Regex("(-0)?-[^-]+$"), "") | ||
| 242 | } catch (e: Exception) { | 253 | } catch (e: Exception) { |
| 243 | logger.error("Cannot find git, defaulting to dummy version number") | 254 | logger.error("Cannot find git") |
| 244 | } | 255 | "" |
| 245 | |||
| 246 | if (System.getenv("GITHUB_ACTIONS") != null) { | ||
| 247 | val gitTag = System.getenv("GIT_TAG_NAME") | ||
| 248 | versionName = gitTag ?: versionName | ||
| 249 | } | 256 | } |
| 250 | |||
| 251 | return versionName | ||
| 252 | } | 257 | } |
| 253 | 258 | ||
| 254 | fun getGitHash(): String { | 259 | fun getGitVersion(): String { |
| 255 | try { | 260 | val versionName = if (System.getenv("GITHUB_ACTIONS") != null) { |
| 256 | val processBuilder = ProcessBuilder("git", "rev-parse", "--short", "HEAD") | 261 | val gitTag = System.getenv("GIT_TAG_NAME") ?: "" |
| 257 | processBuilder.directory(project.rootDir) | 262 | gitTag |
| 258 | val process = processBuilder.start() | 263 | } else { |
| 259 | val inputStream = process.inputStream | 264 | runGitCommand(listOf("git", "describe", "--always", "--long")) |
| 260 | val errorStream = process.errorStream | 265 | .replace(Regex("(-0)?-[^-]+$"), "") |
| 261 | process.waitFor() | ||
| 262 | |||
| 263 | return if (process.exitValue() == 0) { | ||
| 264 | inputStream.bufferedReader() | ||
| 265 | .use { it.readText().trim() } // return the value of gitHash | ||
| 266 | } else { | ||
| 267 | val errorMessage = errorStream.bufferedReader().use { it.readText().trim() } | ||
| 268 | logger.error("Error running git command: $errorMessage") | ||
| 269 | "dummy-hash" // return a dummy hash value in case of an error | ||
| 270 | } | ||
| 271 | } catch (e: Exception) { | ||
| 272 | logger.error("$e: Cannot find git, defaulting to dummy build hash") | ||
| 273 | return "dummy-hash" // return a dummy hash value in case of an error | ||
| 274 | } | 266 | } |
| 267 | return versionName.ifEmpty { "0.0" } | ||
| 275 | } | 268 | } |
| 276 | 269 | ||
| 277 | fun getBranch(): String { | 270 | fun getGitHash(): String = |
| 278 | try { | 271 | runGitCommand(listOf("git", "rev-parse", "--short", "HEAD")).ifEmpty { "dummy-hash" } |
| 279 | val processBuilder = ProcessBuilder("git", "rev-parse", "--abbrev-ref", "HEAD") | 272 | |
| 280 | processBuilder.directory(project.rootDir) | 273 | fun getBranch(): String = |
| 281 | val process = processBuilder.start() | 274 | runGitCommand(listOf("git", "rev-parse", "--abbrev-ref", "HEAD")).ifEmpty { "dummy-hash" } |
| 282 | val inputStream = process.inputStream | ||
| 283 | val errorStream = process.errorStream | ||
| 284 | process.waitFor() | ||
| 285 | |||
| 286 | return if (process.exitValue() == 0) { | ||
| 287 | inputStream.bufferedReader() | ||
| 288 | .use { it.readText().trim() } // return the value of gitHash | ||
| 289 | } else { | ||
| 290 | val errorMessage = errorStream.bufferedReader().use { it.readText().trim() } | ||
| 291 | logger.error("Error running git command: $errorMessage") | ||
| 292 | "dummy-hash" // return a dummy hash value in case of an error | ||
| 293 | } | ||
| 294 | } catch (e: Exception) { | ||
| 295 | logger.error("$e: Cannot find git, defaulting to dummy build hash") | ||
| 296 | return "dummy-hash" // return a dummy hash value in case of an error | ||
| 297 | } | ||
| 298 | } | ||