22091dd808
- add a single AdMob anchored adaptive banner to the free tier - add UMP consent and a privacy-options entry point before ads load - add the one-time Play Billing product `pro_no_ads`; Pro removes the banner and nothing else, every scan/selection/deletion feature stays free - cache the entitlement locally, handle pending purchases, acknowledge and retry acknowledgement, and restore from Play on resume - grandfather paid installs through `legacyPro.cutoffEpochMs`, checking both the new package and the old paid package declared in <queries> - move the Play identity to `de.softwareapp_hb.fotodup.finder.free` while keeping the Kotlin namespace `de.softwareapp_hb.fotodup.finder` - add a debug-only Pro toggle and focused monetisation tests - add AGENTS.md, docs/codemap.md, docs/codemap.mmd and docs/MONETIZATION.md - update README, PRIVACY, CHANGELOG, ROADMAP, store copy and the Play checklist - bump to 1.1.0 / versionCode 4
256 lines
11 KiB
Kotlin
256 lines
11 KiB
Kotlin
import java.util.Properties
|
|
import org.gradle.api.tasks.testing.Test
|
|
|
|
plugins {
|
|
alias(libs.plugins.android.application)
|
|
alias(libs.plugins.kotlin.compose)
|
|
}
|
|
|
|
// Optional release signing.
|
|
//
|
|
// Create a `keystore.properties` file in the project ROOT (it is git-ignored; see
|
|
// keystore.properties.example) with:
|
|
//
|
|
// storeFile=/absolute/path/to/upload-keystore.jks
|
|
// storePassword=********
|
|
// keyAlias=upload
|
|
// keyPassword=********
|
|
//
|
|
// Without that file the release build still runs R8/minification but produces an
|
|
// unsigned APK, which is fine for local checks but cannot be uploaded to Play.
|
|
val keystorePropertiesFile = rootProject.file("keystore.properties")
|
|
val keystoreProperties = Properties().apply {
|
|
if (keystorePropertiesFile.exists()) {
|
|
keystorePropertiesFile.inputStream().use { load(it) }
|
|
}
|
|
}
|
|
val hasReleaseSigning = keystoreProperties.getProperty("storeFile") != null
|
|
|
|
if (hasReleaseSigning) {
|
|
// Fail early and readably instead of letting signReleaseBundle blow up later
|
|
// with an opaque NullPointerException.
|
|
val missing = listOf("storePassword", "keyAlias")
|
|
.filter { keystoreProperties.getProperty(it).isNullOrBlank() }
|
|
check(missing.isEmpty()) {
|
|
"keystore.properties is incomplete — missing: ${missing.joinToString()}"
|
|
}
|
|
}
|
|
|
|
// --- Monetisation configuration --------------------------------------------------------------
|
|
//
|
|
// Real AdMob IDs and the legacy-Pro cutoff are machine/release specific, so they never live in
|
|
// version control. Put them in `local.properties` (git-ignored) or pass them on the command line:
|
|
//
|
|
// admob.appId=ca-app-pub-XXXXXXXXXXXXXXXX~YYYYYYYYYY
|
|
// admob.bannerUnitId=ca-app-pub-XXXXXXXXXXXXXXXX/NNNNNNNNNN
|
|
// legacyPro.cutoffEpochMs=1760918400000
|
|
//
|
|
// The defaults are Google's public test IDs, which are safe to click and produce no revenue.
|
|
// A release build that still uses a test ID is almost certainly a misconfiguration, hence the
|
|
// warning below. See docs/MONETIZATION.md for the complete setup.
|
|
val localProperties = Properties().apply {
|
|
val file = rootProject.file("local.properties")
|
|
if (file.exists()) file.inputStream().use { load(it) }
|
|
}
|
|
|
|
fun configValue(key: String, default: String): String =
|
|
(project.findProperty(key) as String?)?.takeIf { it.isNotBlank() }
|
|
?: localProperties.getProperty(key)?.takeIf { it.isNotBlank() }
|
|
?: default
|
|
|
|
val testAdMobAppId = "ca-app-pub-3940256099942544~3347511713"
|
|
val testAdMobBannerUnitId = "ca-app-pub-3940256099942544/9214589741"
|
|
val adMobAppId = configValue("admob.appId", testAdMobAppId)
|
|
val adMobBannerUnitId = configValue("admob.bannerUnitId", testAdMobBannerUnitId)
|
|
val legacyProCutoffEpochMs = configValue("legacyPro.cutoffEpochMs", "0").toLongOrNull() ?: 0L
|
|
|
|
if (adMobAppId == testAdMobAppId || adMobBannerUnitId == testAdMobBannerUnitId) {
|
|
logger.warn(
|
|
"AdMob is using Google's TEST ids. Set admob.appId and admob.bannerUnitId in " +
|
|
"local.properties (or -Padmob.appId=... -Padmob.bannerUnitId=...) before a release build.",
|
|
)
|
|
}
|
|
if (legacyProCutoffEpochMs <= 0L) {
|
|
logger.warn(
|
|
"legacyPro.cutoffEpochMs is unset: installs that predate the freemium release will NOT " +
|
|
"be grandfathered into Pro. Set it before shipping if the app was sold as a paid app.",
|
|
)
|
|
}
|
|
|
|
android {
|
|
namespace = "de.softwareapp_hb.fotodup.finder"
|
|
compileSdk = 36
|
|
|
|
defaultConfig {
|
|
// The installed package. This is intentionally different from `namespace`:
|
|
// the code package stays `de.softwareapp_hb.fotodup.finder`, while the Play
|
|
// listing is a new app at `.free`. Relative manifest class names resolve
|
|
// against the namespace, so `.MainActivity` still means the existing class.
|
|
applicationId = "de.softwareapp_hb.fotodup.finder.free"
|
|
minSdk = 26
|
|
targetSdk = 36
|
|
versionCode = 4
|
|
versionName = "1.1.0"
|
|
|
|
// AdMob reads its application id from the manifest, so it has to be a placeholder:
|
|
// the value differs between a developer machine, CI and a release build.
|
|
manifestPlaceholders["admobAppId"] = adMobAppId
|
|
|
|
buildConfigField("String", "ADMOB_BANNER_UNIT_ID", "\"$adMobBannerUnitId\"")
|
|
buildConfigField("long", "LEGACY_PRO_CUTOFF_EPOCH_MS", "${legacyProCutoffEpochMs}L")
|
|
|
|
vectorDrawables {
|
|
useSupportLibrary = true
|
|
}
|
|
}
|
|
|
|
signingConfigs {
|
|
if (hasReleaseSigning) {
|
|
create("release") {
|
|
storeFile = file(keystoreProperties.getProperty("storeFile"))
|
|
storePassword = keystoreProperties.getProperty("storePassword")
|
|
keyAlias = keystoreProperties.getProperty("keyAlias")
|
|
// Falls back to the store password. That matches reality: PKCS12
|
|
// keystores (the default on modern JDKs) cannot have a key password
|
|
// that differs from the store password, and leaving this null makes
|
|
// AGP's signReleaseBundle crash with an NPE.
|
|
keyPassword = keystoreProperties.getProperty("keyPassword")
|
|
?: keystoreProperties.getProperty("storePassword")
|
|
}
|
|
}
|
|
}
|
|
|
|
buildTypes {
|
|
debug {
|
|
applicationIdSuffix = ".debug"
|
|
versionNameSuffix = "-debug"
|
|
}
|
|
release {
|
|
if (hasReleaseSigning) {
|
|
signingConfig = signingConfigs.getByName("release")
|
|
}
|
|
isMinifyEnabled = true
|
|
isShrinkResources = true
|
|
proguardFiles(
|
|
getDefaultProguardFile("proguard-android-optimize.txt"),
|
|
"proguard-rules.pro",
|
|
)
|
|
}
|
|
}
|
|
|
|
compileOptions {
|
|
sourceCompatibility = JavaVersion.VERSION_17
|
|
targetCompatibility = JavaVersion.VERSION_17
|
|
}
|
|
|
|
buildFeatures {
|
|
compose = true
|
|
// AdMob unit id + legacy-Pro cutoff are injected here.
|
|
buildConfig = true
|
|
}
|
|
|
|
testOptions {
|
|
unitTests {
|
|
// Robolectric needs the merged resources and manifest to stand up the framework.
|
|
isIncludeAndroidResources = true
|
|
}
|
|
}
|
|
|
|
packaging {
|
|
resources {
|
|
excludes += "/META-INF/{AL2.0,LGPL2.1}"
|
|
}
|
|
}
|
|
|
|
lint {
|
|
// Dependency versions are pinned deliberately — Compose 1.12+/Coil 3.6+ need
|
|
// compileSdk 37, which AGP 9.1 does not support yet (see the README version
|
|
// note). These advisories are noise rather than signal here.
|
|
disable += setOf(
|
|
"GradleDependency",
|
|
"AndroidGradlePluginVersion",
|
|
"NewerVersionAvailable",
|
|
)
|
|
}
|
|
}
|
|
|
|
kotlin {
|
|
compilerOptions {
|
|
// With AGP built-in Kotlin this already defaults to
|
|
// android.compileOptions.targetCompatibility; set explicitly for clarity.
|
|
jvmTarget = org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_17
|
|
}
|
|
}
|
|
|
|
// `java.awt` is used by the similarity benchmark (headless), and the benchmark itself is
|
|
// opt-in. Gradle's -D only reaches the Gradle JVM, so the flags are forwarded explicitly.
|
|
// Run it with:
|
|
// ./gradlew :app:testDebugUnitTest --tests '*SimilarityBenchmarkTest*' -DfotoBench=true
|
|
tasks.withType<Test>().configureEach {
|
|
systemProperty("java.awt.headless", "true")
|
|
// Robolectric reflects into JDK internals (notably java.io.FileDescriptor), which the module
|
|
// system blocks from JDK 17 onwards. Without these it fails with "Failed to interact with raw
|
|
// FileDescriptor internals".
|
|
jvmArgs(
|
|
"--add-opens=java.base/java.io=ALL-UNNAMED",
|
|
"--add-opens=java.base/java.lang=ALL-UNNAMED",
|
|
"--add-opens=java.base/java.lang.reflect=ALL-UNNAMED",
|
|
"--add-opens=java.base/java.util=ALL-UNNAMED",
|
|
"--add-opens=java.base/java.text=ALL-UNNAMED",
|
|
"--add-opens=java.base/java.nio=ALL-UNNAMED",
|
|
"--add-opens=java.base/sun.nio.ch=ALL-UNNAMED",
|
|
// Robolectric reaches FileDescriptor internals through jdk.internal.access.SharedSecrets, and
|
|
// that needs an *export* rather than an *open*: without it the run dies with
|
|
// "IllegalAccessException ... module java.base does not export jdk.internal.access".
|
|
"--add-exports=java.base/jdk.internal.access=ALL-UNNAMED",
|
|
"--add-exports=java.base/jdk.internal.misc=ALL-UNNAMED",
|
|
"--add-exports=java.base/jdk.internal.reflect=ALL-UNNAMED",
|
|
)
|
|
systemProperty("fotoBench", providers.systemProperty("fotoBench").orNull ?: "false")
|
|
providers.systemProperty("fotoBench.dir").orNull?.let { systemProperty("fotoBench.dir", it) }
|
|
providers.systemProperty("fotoBench.count").orNull?.let { systemProperty("fotoBench.count", it) }
|
|
providers.systemProperty("fotoBench.scenes").orNull?.let { systemProperty("fotoBench.scenes", it) }
|
|
providers.systemProperty("fotoBench.density").orNull?.let { systemProperty("fotoBench.density", it) }
|
|
providers.systemProperty("fotoBench.max").orNull?.let { systemProperty("fotoBench.max", it) }
|
|
providers.systemProperty("fotoLocal.dir").orNull?.let { systemProperty("fotoLocal.dir", it) }
|
|
providers.systemProperty("fotoScale").orNull?.let { systemProperty("fotoScale", it) }
|
|
// Real-photo runs hold hundreds of decoded images in memory at once.
|
|
maxHeapSize = "2g"
|
|
testLogging { showStandardStreams = true }
|
|
}
|
|
|
|
dependencies {
|
|
implementation(libs.androidx.core.ktx)
|
|
// EXIF orientation, so a photo hashes the same whichever decode path served it.
|
|
implementation(libs.androidx.exifinterface)
|
|
|
|
implementation(libs.androidx.lifecycle.runtime.ktx)
|
|
implementation(libs.androidx.lifecycle.runtime.compose)
|
|
implementation(libs.androidx.lifecycle.viewmodel.compose)
|
|
|
|
implementation(libs.androidx.activity.compose)
|
|
|
|
implementation(platform(libs.androidx.compose.bom))
|
|
implementation(libs.androidx.compose.ui)
|
|
implementation(libs.androidx.compose.ui.graphics)
|
|
implementation(libs.androidx.compose.ui.tooling.preview)
|
|
implementation(libs.androidx.compose.material3)
|
|
implementation(libs.androidx.compose.material.icons.core)
|
|
|
|
implementation(libs.kotlinx.coroutines.android)
|
|
implementation(libs.coil.compose)
|
|
|
|
// Free tier: AdMob banner + UMP consent. Pro tier: one-time Play Billing product.
|
|
// The ads SDK merges INTERNET, ACCESS_NETWORK_STATE, AD_ID and the Privacy Sandbox
|
|
// permissions into the release manifest; billing-ktx merges com.android.vending.BILLING.
|
|
implementation(libs.play.services.ads)
|
|
implementation(libs.user.messaging.platform)
|
|
implementation(libs.billing.ktx)
|
|
|
|
debugImplementation(libs.androidx.compose.ui.tooling)
|
|
|
|
testImplementation(libs.junit)
|
|
// Runs the real Android framework on the JVM, so the data layer is testable without a device.
|
|
testImplementation(libs.robolectric)
|
|
}
|