Skip to content

Commit

Permalink
fix: Improve detection of unset API keys
Browse files Browse the repository at this point in the history
Improvements to the detection of unset API keys, providing clearer error messages and guidance to developers.

The PlacesAutocompleteTextFieldTest has been updated to account for the new default line limits.

Updates the versions of the following dependencies:

* MapsCompose
* Places
* AGP
* Compose BOM
* Kotlin
* Material
* Other dependencies as needed
  • Loading branch information
dkhawk committed Jan 7, 2025
1 parent f419ed5 commit 39898dc
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 40 deletions.
40 changes: 20 additions & 20 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
[versions]
accompanistPermissions = "0.34.0"
activityCompose = "1.9.2"
agp = "8.6.1"
accompanistPermissions = "0.37.0"
activityCompose = "1.9.3"
agp = "8.7.3"
appcompat = "1.7.0"
composeBom = "2024.09.02"
coreKtx = "1.13.1"
composeBom = "2024.12.01"
coreKtx = "1.15.0"
dokka = "1.9.20"
espressoCore = "3.6.1"
gson = "2.10.1"
hiltVersion = "2.51.1"
hiltVersion = "2.54"
jacoco-plugin = "0.2.1"
junit = "4.13.2"
junitVersion = "1.2.1"
kotlin = "2.0.0"
kotlinReflect = "2.0.0"
kotlinxCoroutinesPlayServices = "1.8.1"
ksp = "2.0.0-1.0.21"
lifecycleRuntimeKtx = "2.8.6"
lifecycleViewmodelCompose = "2.8.6"
mapsCompose = "6.1.0"
kotlin = "2.1.0"
kotlinReflect = "2.1.0"
kotlinxCoroutinesPlayServices = "1.9.0"
ksp = "2.1.0-1.0.29"
lifecycleRuntimeKtx = "2.8.7"
lifecycleViewmodelCompose = "2.8.7"
mapsCompose = "6.4.1"
mapsUtilsKtx = "5.1.1"
materialVersion = "1.13.0-alpha06"
navigationCompose = "2.8.1"
materialVersion = "1.13.0-alpha09"
navigationCompose = "2.8.5"
org-jacoco-core = "0.8.11"
places = "4.0.0"
robolectric = "4.12.2"
places = "4.1.0"
robolectric = "4.14.1"
secretsGradlePlugin = "2.0.1"
truth = "1.4.2"
uiTestAndroid = "1.7.2"
uiToolingVersion = "1.7.2"
truth = "1.4.4"
uiTestAndroid = "1.7.6"
uiToolingVersion = "1.7.6"

[libraries]
accompanist-permissions = { module = "com.google.accompanist:accompanist-permissions", version.ref = "accompanistPermissions" }
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Mon Jul 08 16:30:21 MDT 2024
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.11.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
16 changes: 9 additions & 7 deletions places-compose-demo/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,22 @@ android {
enableAndroidTestCoverage = true
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8

java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(21))
}
}

kotlinOptions {
jvmTarget = "1.8"
jvmTarget = "21"
}

buildFeatures {
compose = true
buildConfig = true
}
composeOptions {
kotlinCompilerExtensionVersion = "1.5.1"
}

packaging {
resources {
excludes += "/META-INF/{AL2.0,LGPL2.1}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,23 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import com.google.android.libraries.places.compose.demo.data.repositories.ApiKeyProvider
import com.google.android.libraries.places.compose.demo.presentation.autocomplete.AutocompleteActivity
import com.google.android.libraries.places.compose.demo.presentation.landmark.LandmarkSelectionActivity
import com.google.android.libraries.places.compose.demo.presentation.addresscompletion.AddressCompletionActivity
import com.google.android.libraries.places.compose.demo.presentation.minimal.PlacesAutocompleteMinimalActivity
import dagger.hilt.android.AndroidEntryPoint
import javax.inject.Inject

@AndroidEntryPoint
class MainActivity : ComponentActivity() {
@Inject
lateinit var apiKeyProvider: ApiKeyProvider

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
enableEdgeToEdge()

setContent {
AndroidPlacesComposeDemoTheme {
Surface(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ package com.google.android.libraries.places.compose.demo.data.repositories

import android.content.Context
import android.content.pm.PackageManager
import android.widget.Toast
import com.google.android.libraries.places.compose.demo.BuildConfig

/**
Expand Down Expand Up @@ -47,4 +48,15 @@ class ApiKeyProvider(private val context: Context) {
}
return mapsApiKey
}

init {
if (placesApiKey == "DEFAULT_API_KEY" || (getMapsApiKeyFromManifest() == "DEFAULT_API_KEY")) {
Toast.makeText(
context,
"One or more API keys have not been set. Please see the README.md file.",
Toast.LENGTH_LONG
).show()
error("One or more API keys have not been set. Please see the README.md file.")
}
}
}
25 changes: 15 additions & 10 deletions places-compose/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@ android {
}

namespace = "com.google.android.libraries.places.compose"
compileSdk = 34
compileSdk = 35

defaultConfig {
minSdk = 21

minSdk = 24
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles("consumer-rules.pro")
}
Expand All @@ -29,19 +28,21 @@ android {
)
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8

java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(21))
}
}

kotlinOptions {
jvmTarget = "21"
}

buildFeatures {
buildConfig = true
compose = true
}

kotlinOptions {
jvmTarget = "1.8"
}
}

dependencies {
Expand All @@ -54,6 +55,7 @@ dependencies {
testImplementation(libs.androidx.ui.test.android)
androidTestImplementation(libs.androidx.junit)
androidTestImplementation(libs.androidx.espresso.core)
androidTestImplementation(libs.androidx.ui.test.android)

implementation(libs.gson)
implementation(libs.kotlinx.coroutines.play.services)
Expand All @@ -76,4 +78,7 @@ dependencies {

debugImplementation(libs.androidx.ui.test.manifest)
testImplementation(libs.robolectric)

androidTestImplementation(libs.ui.test.junit4)
// debugImplementation(libs.ui.test.manifest)
}
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,22 @@ class PlacesAutocompleteTextFieldTest {
var isExpanded by remember { mutableStateOf(false) }
AutocompletePlaceRow(
autocompletePlace = testPlace.copy(
primaryText = SpannableString("Very long primary text that should be truncated"),
secondaryText = SpannableString("Very long secondary text that should be truncated")
primaryText = SpannableString(
"Very long primary text that should be truncated" +
"There is no strife, no prejudice, no national conflict in outer " +
"space as yet. Its hazards are hostile to us all. Its conquest " +
"deserves the best of all mankind, and its opportunity for " +
"peaceful cooperation many never come again. " +
"But why, some say, the moon? Why choose this as our goal? " +
"And they may well ask why climb the highest mountain?"
),
secondaryText = SpannableString(
"Very long secondary text that should be truncated" +
"It is for these reasons that I regard the decision last year to" +
"shift our efforts in space from low to high gear as among the most " +
"important decisions that will be made during my incumbency in the " +
"office of the Presidency."
)
),
isSelected = false,
onPlaceSelected = {},
Expand Down

0 comments on commit 39898dc

Please sign in to comment.