Skip to content

Commit

Permalink
Cleaned up BuildConfig not to expose unused secrets.
Browse files Browse the repository at this point in the history
  • Loading branch information
HLCaptain committed Jul 31, 2024
1 parent 0594a75 commit 901c0d4
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 38 deletions.
78 changes: 41 additions & 37 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2024 Balázs Püspök-Kiss (Illyan)
* Copyright (c) 2022-2024 Balázs Püspök-Kiss (Illyan)
*
* Jay is a driver behaviour analytics app.
*
Expand All @@ -16,25 +16,7 @@
* If not, see <https://www.gnu.org/licenses/>.
*/

import com.google.android.libraries.mapsplatform.secrets_gradle_plugin.loadPropertiesFile

/*
* Copyright (c) 2022-2023 Balázs Püspök-Kiss (Illyan)
*
* Jay is a driver behaviour analytics app.
*
* This file is part of Jay.
*
* Jay is free software: you can redistribute it and/or modify it under the
* terms of the GNU General Public License as published by the Free Software
* Foundation, either version 3 of the License, or (at your option) any later version.
* Jay is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with Jay.
* If not, see <https://www.gnu.org/licenses/>.
*/
import org.jetbrains.kotlin.konan.properties.loadProperties

plugins {
alias(libs.plugins.android.application)
Expand All @@ -52,6 +34,8 @@ plugins {
alias(libs.plugins.compose.compiler)
}

val localProperties = loadProperties("$projectDir/../local.properties")

android {
compileSdk = 35

Expand All @@ -71,22 +55,20 @@ android {
}

signingConfigs {
val properties = loadPropertiesFile("../local.properties").toMap()

val debugStorePath = properties["DEBUG_KEY_PATH"].toString()
val debugKeyAlias = properties["DEBUG_KEY_ALIAS"].toString()
val debugStorePassword = properties["DEBUG_KEYSTORE_PASSWORD"].toString()
val debugKeyPassword = properties["DEBUG_KEY_PASSWORD"].toString()
val debugStorePath = localProperties["DEBUG_KEY_PATH"].toString()
val debugKeyAlias = localProperties["DEBUG_KEY_ALIAS"].toString()
val debugStorePassword = localProperties["DEBUG_KEYSTORE_PASSWORD"].toString()
val debugKeyPassword = localProperties["DEBUG_KEY_PASSWORD"].toString()
getByName("debug") {
storeFile = file(debugStorePath)
keyAlias = debugKeyAlias
storePassword = debugStorePassword
keyPassword = debugKeyPassword
}
val releaseStorePath = properties["RELEASE_KEY_PATH"].toString()
val releaseKeyAlias = properties["RELEASE_KEY_ALIAS"].toString()
val releaseStorePassword = properties["RELEASE_KEYSTORE_PASSWORD"].toString()
val releaseKeyPassword = properties["RELEASE_KEY_PASSWORD"].toString()
val releaseStorePath = localProperties["RELEASE_KEY_PATH"].toString()
val releaseKeyAlias = localProperties["RELEASE_KEY_ALIAS"].toString()
val releaseStorePassword = localProperties["RELEASE_KEYSTORE_PASSWORD"].toString()
val releaseKeyPassword = localProperties["RELEASE_KEY_PASSWORD"].toString()
create("release") {
storeFile = file(releaseStorePath)
keyAlias = releaseKeyAlias
Expand All @@ -96,20 +78,23 @@ android {
}

buildTypes {
val mapboxAccessToken = properties["MAPBOX_ACCESS_TOKEN"].toString()
val mapboxDownloadsToken = properties["MAPBOX_DOWNLOADS_TOKEN"].toString()
val mapboxSdkRegistryToken = properties["SDK_REGISTRY_TOKEN"].toString()
val mapboxAccessToken = localProperties["MAPBOX_ACCESS_TOKEN"].toString()
val mapboxDownloadsToken = localProperties["MAPBOX_DOWNLOADS_TOKEN"].toString()
val mapboxSdkRegistryToken = localProperties["SDK_REGISTRY_TOKEN"].toString()
val admobAppId = localProperties["ADMOB_APPLICATION_ID"].toString()
getByName("debug") {
isDebuggable = true
buildConfigField("String", "MapboxAccessToken", "\"$mapboxAccessToken\"")
buildConfigField("String", "MapboxDownloadsToken", "\"$mapboxDownloadsToken\"")
buildConfigField("String", "MapboxSdkRegistryToken", "\"$mapboxSdkRegistryToken\"")
buildConfigField("String", "MAPBOX_ACCESS_TOKEN", "\"$mapboxAccessToken\"")
buildConfigField("String", "MAPBOX_DOWNLOADS_TOKEN", "\"$mapboxDownloadsToken\"")
buildConfigField("String", "SDK_REGISTRY_TOKEN", "\"$mapboxSdkRegistryToken\"")
buildConfigField("String", "ADMOB_APPLICATION_ID", "\"$admobAppId\"")
}
getByName("release") {
isDebuggable = false
isMinifyEnabled = true
isShrinkResources = true
buildConfigField("String", "MapboxAccessToken", "\"$mapboxAccessToken\"")
buildConfigField("String", "MAPBOX_ACCESS_TOKEN", "\"$mapboxAccessToken\"")
buildConfigField("String", "ADMOB_APPLICATION_ID", "\"$admobAppId\"")
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
Expand Down Expand Up @@ -293,3 +278,22 @@ hilt {
room {
schemaDirectory("$projectDir/schemas")
}

secrets {
// Ignore everything, except ADMOB_APPLICATION_ID for AndroidManifest.xml
ignoreList.addAll(
listOf(
"RELEASE_KEYSTORE_PASSWORD*",
"RELEASE_KEY_PASSWORD*",
"RELEASE_KEY_ALIAS*",
"RELEASE_KEY_PATH*",
"DEBUG_KEYSTORE_PASSWORD*",
"DEBUG_KEY_PASSWORD*",
"DEBUG_KEY_ALIAS*",
"DEBUG_KEY_PATH*",
"MAPBOX_DOWNLOADS_TOKEN*",
"SDK_REGISTRY_TOKEN*",
"MAPBOX_ACCESS_TOKEN*"
)
)
}
2 changes: 1 addition & 1 deletion app/src/main/java/illyan/jay/MainApplication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class MainApplication : Application() {
override fun onCreate() {
super.onCreate()

MapboxOptions.accessToken = BuildConfig.MapboxAccessToken
MapboxOptions.accessToken = BuildConfig.MAPBOX_ACCESS_TOKEN
initLogging()
initAds()
}
Expand Down

0 comments on commit 901c0d4

Please sign in to comment.