Skip to content

Commit

Permalink
Add staging build variant, move staging URL out of source control
Browse files Browse the repository at this point in the history
Change-Id: I9388f8d2adc4800749fc7e5e79c2d165938401c4
  • Loading branch information
dturner committed May 11, 2022
1 parent d945a00 commit 9bb7f9d
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 1 deletion.
9 changes: 9 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@ buildscript {
classpath(libs.kotlin.gradlePlugin)
classpath(libs.kotlin.serializationPlugin)
classpath(libs.hilt.gradlePlugin)
classpath(libs.secrets.gradlePlugin)
}
}
21 changes: 21 additions & 0 deletions core-network/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -68,7 +69,7 @@ private interface RetrofitNiANetworkApi {
): List<NetworkChangeList>
}

private const val NiABaseUrl = "https://staging-url.com/"
private const val NiABaseUrl = BuildConfig.BACKEND_URL

/**
* Wrapper for data provided from the [NiABaseUrl]
Expand Down
2 changes: 2 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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]
Expand Down
4 changes: 4 additions & 0 deletions secrets.defaults.properties
Original file line number Diff line number Diff line change
@@ -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"

0 comments on commit 9bb7f9d

Please sign in to comment.