From 9bb7f9d8a7f2ef5806aeddcd06e5be3a6c12249d Mon Sep 17 00:00:00 2001 From: Don Turner Date: Mon, 9 May 2022 21:29:50 +0100 Subject: [PATCH] Add staging build variant, move staging URL out of source control Change-Id: I9388f8d2adc4800749fc7e5e79c2d165938401c4 --- app/build.gradle.kts | 9 ++++ build.gradle.kts | 1 + core-network/build.gradle.kts | 21 +++++++++ .../core/network/di/NetworkModule.kt | 45 +++++++++++++++++++ .../network/retrofit/RetrofitNiANetwork.kt | 3 +- .../core/network/di/NetworkModule.kt | 0 gradle/libs.versions.toml | 2 + secrets.defaults.properties | 4 ++ 8 files changed, 84 insertions(+), 1 deletion(-) create mode 100644 core-network/src/debug/java/com/google/samples/apps/nowinandroid/core/network/di/NetworkModule.kt rename core-network/src/{main => release}/java/com/google/samples/apps/nowinandroid/core/network/di/NetworkModule.kt (100%) create mode 100644 secrets.defaults.properties diff --git a/app/build.gradle.kts b/app/build.gradle.kts index cc60c587f..c360b1447 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -37,6 +37,9 @@ android { } buildTypes { + val debug by getting { + applicationIdSuffix = ".debug" + } val release by getting { isMinifyEnabled = true proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro") @@ -47,6 +50,12 @@ android { matchingFallbacks.add("release") proguardFiles("benchmark-rules.pro") } + val staging by creating { + initWith(debug) + signingConfig = signingConfigs.getByName("debug") + matchingFallbacks.add("debug") + applicationIdSuffix = ".staging" + } } packagingOptions { resources { diff --git a/build.gradle.kts b/build.gradle.kts index d0d8f45bf..052e34df4 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -25,5 +25,6 @@ buildscript { classpath(libs.kotlin.gradlePlugin) classpath(libs.kotlin.serializationPlugin) classpath(libs.hilt.gradlePlugin) + classpath(libs.secrets.gradlePlugin) } } diff --git a/core-network/build.gradle.kts b/core-network/build.gradle.kts index 0eb1889bc..9b3303f4d 100644 --- a/core-network/build.gradle.kts +++ b/core-network/build.gradle.kts @@ -20,6 +20,27 @@ plugins { id("kotlinx-serialization") id("dagger.hilt.android.plugin") id("nowinandroid.spotless") + id("com.google.android.libraries.mapsplatform.secrets-gradle-plugin") +} + +android { + buildTypes { + val staging by creating { + initWith(getByName("debug")) + matchingFallbacks.add("debug") + } + } + // Force the staging variant to use the release source directory. This is necessary so that the + // staging variant uses the remote network. + sourceSets { + getByName("staging") { + java.srcDir("src/release/java") + } + } +} + +secrets { + defaultPropertiesFileName = "secrets.defaults.properties" } dependencies { diff --git a/core-network/src/debug/java/com/google/samples/apps/nowinandroid/core/network/di/NetworkModule.kt b/core-network/src/debug/java/com/google/samples/apps/nowinandroid/core/network/di/NetworkModule.kt new file mode 100644 index 000000000..2b906063c --- /dev/null +++ b/core-network/src/debug/java/com/google/samples/apps/nowinandroid/core/network/di/NetworkModule.kt @@ -0,0 +1,45 @@ +/* + * Copyright 2022 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.google.samples.apps.nowinandroid.core.network.di + +import com.google.samples.apps.nowinandroid.core.network.NiANetwork +import com.google.samples.apps.nowinandroid.core.network.fake.FakeNiANetwork +import dagger.Binds +import dagger.Module +import dagger.Provides +import dagger.hilt.InstallIn +import dagger.hilt.components.SingletonComponent +import javax.inject.Singleton +import kotlinx.serialization.json.Json + +@Module +@InstallIn(SingletonComponent::class) +interface NetworkModule { + + @Binds + fun bindsNiANetwork( + niANetwork: FakeNiANetwork + ): NiANetwork + + companion object { + @Provides + @Singleton + fun providesNetworkJson(): Json = Json { + ignoreUnknownKeys = true + } + } +} diff --git a/core-network/src/main/java/com/google/samples/apps/nowinandroid/core/network/retrofit/RetrofitNiANetwork.kt b/core-network/src/main/java/com/google/samples/apps/nowinandroid/core/network/retrofit/RetrofitNiANetwork.kt index 1c9381a06..e6837f5bc 100644 --- a/core-network/src/main/java/com/google/samples/apps/nowinandroid/core/network/retrofit/RetrofitNiANetwork.kt +++ b/core-network/src/main/java/com/google/samples/apps/nowinandroid/core/network/retrofit/RetrofitNiANetwork.kt @@ -16,6 +16,7 @@ package com.google.samples.apps.nowinandroid.core.network.retrofit +import com.google.samples.apps.nowinandroid.core.network.BuildConfig import com.google.samples.apps.nowinandroid.core.network.NiANetwork import com.google.samples.apps.nowinandroid.core.network.model.NetworkAuthor import com.google.samples.apps.nowinandroid.core.network.model.NetworkChangeList @@ -68,7 +69,7 @@ private interface RetrofitNiANetworkApi { ): List } -private const val NiABaseUrl = "https://staging-url.com/" +private const val NiABaseUrl = BuildConfig.BACKEND_URL /** * Wrapper for data provided from the [NiABaseUrl] diff --git a/core-network/src/main/java/com/google/samples/apps/nowinandroid/core/network/di/NetworkModule.kt b/core-network/src/release/java/com/google/samples/apps/nowinandroid/core/network/di/NetworkModule.kt similarity index 100% rename from core-network/src/main/java/com/google/samples/apps/nowinandroid/core/network/di/NetworkModule.kt rename to core-network/src/release/java/com/google/samples/apps/nowinandroid/core/network/di/NetworkModule.kt diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index f2c5d4dc6..99acfa39a 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -41,6 +41,7 @@ protobufPlugin = "0.8.18" retrofit = "2.9.0" retrofitKotlinxSerializationJson = "0.8.0" room = "2.4.1" +secrets = "2.0.1" spotless = "6.3.0" turbine = "0.7.0" @@ -108,6 +109,7 @@ retrofit-kotlin-serialization = { group = "com.jakewharton.retrofit", name = "re room-runtime = { group = "androidx.room", name = "room-runtime", version.ref = "room" } room-ktx = { group = "androidx.room", name = "room-ktx", version.ref = "room" } room-compiler = { group = "androidx.room", name = "room-compiler", version.ref = "room" } +secrets-gradlePlugin = { group = "com.google.android.libraries.mapsplatform.secrets-gradle-plugin", name = "secrets-gradle-plugin", version.ref = "secrets" } spotless-gradlePlugin = { group = "com.diffplug.spotless", name = "spotless-plugin-gradle", version.ref = "spotless" } [plugins] diff --git a/secrets.defaults.properties b/secrets.defaults.properties new file mode 100644 index 000000000..3b5457bd9 --- /dev/null +++ b/secrets.defaults.properties @@ -0,0 +1,4 @@ +## This file provides default values to modules using the secrets-gradle-plugin. It is necessary +# because the secrets properties file is not under source control so CI builds will fail without +# default values. +BACKEND_URL="http://example.com" \ No newline at end of file