Files
logic-puzzle/android/app/build.gradle.kts
T

114 lines
4.9 KiB
Kotlin

import java.util.Base64
import java.util.Properties
plugins {
id("com.android.application")
// The Flutter Gradle Plugin must be applied after the Android and Kotlin Gradle plugins.
id("dev.flutter.flutter-gradle-plugin")
}
val uploadProperties = Properties()
val uploadPropertiesPath = providers.gradleProperty("LUMEN_UPLOAD_PROPERTIES")
.orElse(providers.environmentVariable("LUMEN_UPLOAD_PROPERTIES"))
.orNull
if (uploadPropertiesPath != null) {
val propertiesFile = file(uploadPropertiesPath)
require(propertiesFile.isFile) { "Upload signing properties file does not exist." }
propertiesFile.inputStream().use { uploadProperties.load(it) }
}
android {
namespace = "com.lumen.daily"
compileSdk = flutter.compileSdkVersion
ndkVersion = flutter.ndkVersion
compileOptions {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
defaultConfig {
applicationId = "de.softwareapp_hb.lumen.daily"
// You can update the following values to match your application needs.
// For more information, see: https://flutter.dev/to/review-gradle-config.
minSdk = 24
targetSdk = flutter.targetSdkVersion
// Uses the version code from pubspec.yaml. When using split APKs, 1000 * ABI_VERSION
// is added automatically by Flutter. (https://developer.android.com/studio/build/configure-apk-splits#configure-APK-versions)
// You can force using the value of versionCode by specifying the `-P force-version-code-ignoring-abi=true`
// flag during build.
versionCode = flutter.versionCode
versionName = flutter.versionName
manifestPlaceholders["admobAppId"] = providers.gradleProperty("ADMOB_APP_ID").getOrElse("ca-app-pub-3940256099942544~3347511713")
}
signingConfigs {
create("upload") {
uploadProperties.getProperty("storeFile")?.let { storeFile = file(it) }
storePassword = uploadProperties.getProperty("storePassword")
keyAlias = uploadProperties.getProperty("keyAlias")
keyPassword = uploadProperties.getProperty("keyPassword")
}
}
flavorDimensions += "edition"
productFlavors {
create("prod") { dimension = "edition"; signingConfig = signingConfigs.getByName("upload") }
create("qa") { dimension = "edition"; applicationId = "com.lumen.daily.qa"; versionNameSuffix = "-qa" }
create("check") { dimension = "edition"; applicationId = "com.lumen.daily.check"; versionNameSuffix = "-check" }
}
buildTypes {
debug { signingConfig = signingConfigs.getByName("debug") }
release {
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
}
}
}
kotlin {
compilerOptions {
jvmTarget = org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_17
}
}
flutter {
source = "../.."
}
// Never produce a production release with sample ad IDs or a debug key.
gradle.taskGraph.whenReady {
if (allTasks.any { it.project == project && it.name.contains("ProdRelease", ignoreCase = true) }) {
val appId = providers.gradleProperty("ADMOB_APP_ID").orNull ?: ""
val validAppId = Regex("ca-app-pub-[0-9]{16}~[0-9]{10}")
require(validAppId.matches(appId) && !appId.startsWith("ca-app-pub-3940256099942544~")) {
"Production release requires a real ADMOB_APP_ID Gradle property."
}
val defines = providers.gradleProperty("dart-defines").orNull.orEmpty()
.split(",").filter { it.isNotBlank() }.mapNotNull {
runCatching { String(Base64.getDecoder().decode(it), Charsets.UTF_8) }.getOrNull()
}.mapNotNull { value ->
val index = value.indexOf('=')
if (index < 0) null else value.substring(0, index) to value.substring(index + 1)
}.toMap()
val validUnitId = Regex("ca-app-pub-[0-9]{16}/[0-9]{10}")
for (name in listOf("ADMOB_REWARDED_ID", "ADMOB_INTERSTITIAL_ID")) {
val id = defines[name].orEmpty()
require(validUnitId.matches(id) && !id.startsWith("ca-app-pub-3940256099942544/")) {
"Production release requires a real $name Dart define."
}
}
for (name in listOf("storeFile", "storePassword", "keyAlias", "keyPassword")) {
require(!uploadProperties.getProperty(name).isNullOrBlank()) {
"Production release requires $name in the upload signing properties file."
}
}
require(file(uploadProperties.getProperty("storeFile")).isFile) {
"Production upload keystore does not exist."
}
// Age-appropriate consent and advertising are implemented in the app:
// under-13 and unknown-age players never initialize the ad SDK, teens
// receive child-directed treatment, and adults receive standard
// treatment. Real AdMob IDs and upload signing remain mandatory.
}
}