From 0289bb42ba6192c01df4a9e2fb15529c57977d5a Mon Sep 17 00:00:00 2001 From: Dale Hawkins <107309+dkhawk@users.noreply.github.com> Date: Wed, 8 Jan 2025 12:46:47 -0700 Subject: [PATCH] fix: Improve detection of unset API keys (#31) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: Improve detection of unset API keys 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 * chore: updates java version for lint and docs workflows * fix: setting Java version to 17 --------- Co-authored-by: Enrique López Mañas --- .github/workflows/docs.yml | 6 +-- .github/workflows/lint-report.yml | 6 +-- gradle/libs.versions.toml | 40 +++++++++---------- gradle/wrapper/gradle-wrapper.properties | 2 +- places-compose-demo/build.gradle.kts | 16 ++++---- .../places/compose/demo/MainActivity.kt | 6 +++ .../demo/data/repositories/ApiKeyProvider.kt | 12 ++++++ places-compose/build.gradle.kts | 24 ++++++----- .../PlacesAutocompleteTextFieldTest.kt | 18 ++++++++- 9 files changed, 84 insertions(+), 46 deletions(-) diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 4661c24..44339a8 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -34,10 +34,10 @@ jobs: - name: Gradle Wrapper Validation uses: gradle/wrapper-validation-action@v1.0.4 - - name: Set up JDK 17 - uses: actions/setup-java@v2.3.1 + - name: Set up JDK 21 + uses: actions/setup-java@v4.2.1 with: - java-version: '17' + java-version: '21' distribution: 'adopt' # Run dokka and create tar diff --git a/.github/workflows/lint-report.yml b/.github/workflows/lint-report.yml index dffa97a..37db560 100644 --- a/.github/workflows/lint-report.yml +++ b/.github/workflows/lint-report.yml @@ -30,11 +30,11 @@ jobs: - name: Checkout code uses: actions/checkout@v3 - - name: Set up JDK 17 - uses: actions/setup-java@v3 + - name: Set up JDK 21 + uses: actions/setup-java@v4.2.1 with: + java-version: '21' distribution: 'adopt' - java-version: '17' - name: Run Android Lint run: ./gradlew lint diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 1093cca..e53b4c2 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -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" } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index d998367..e021026 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -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 diff --git a/places-compose-demo/build.gradle.kts b/places-compose-demo/build.gradle.kts index b61da27..ceac3af 100644 --- a/places-compose-demo/build.gradle.kts +++ b/places-compose-demo/build.gradle.kts @@ -43,20 +43,22 @@ android { enableAndroidTestCoverage = true } } - compileOptions { - sourceCompatibility = JavaVersion.VERSION_1_8 - targetCompatibility = JavaVersion.VERSION_1_8 + + java { + toolchain { + languageVersion.set(JavaLanguageVersion.of(17)) + } } + kotlinOptions { - jvmTarget = "1.8" + jvmTarget = "17" } + buildFeatures { compose = true buildConfig = true } - composeOptions { - kotlinCompilerExtensionVersion = "1.5.1" - } + packaging { resources { excludes += "/META-INF/{AL2.0,LGPL2.1}" diff --git a/places-compose-demo/src/main/java/com/google/android/libraries/places/compose/demo/MainActivity.kt b/places-compose-demo/src/main/java/com/google/android/libraries/places/compose/demo/MainActivity.kt index 866d55d..0440b71 100644 --- a/places-compose-demo/src/main/java/com/google/android/libraries/places/compose/demo/MainActivity.kt +++ b/places-compose-demo/src/main/java/com/google/android/libraries/places/compose/demo/MainActivity.kt @@ -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( diff --git a/places-compose-demo/src/main/java/com/google/android/libraries/places/compose/demo/data/repositories/ApiKeyProvider.kt b/places-compose-demo/src/main/java/com/google/android/libraries/places/compose/demo/data/repositories/ApiKeyProvider.kt index 3203d22..0db4f22 100644 --- a/places-compose-demo/src/main/java/com/google/android/libraries/places/compose/demo/data/repositories/ApiKeyProvider.kt +++ b/places-compose-demo/src/main/java/com/google/android/libraries/places/compose/demo/data/repositories/ApiKeyProvider.kt @@ -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 /** @@ -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.") + } + } } diff --git a/places-compose/build.gradle.kts b/places-compose/build.gradle.kts index 4f20db4..7777727 100644 --- a/places-compose/build.gradle.kts +++ b/places-compose/build.gradle.kts @@ -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") } @@ -29,19 +28,21 @@ android { ) } } - compileOptions { - sourceCompatibility = JavaVersion.VERSION_1_8 - targetCompatibility = JavaVersion.VERSION_1_8 + + java { + toolchain { + languageVersion.set(JavaLanguageVersion.of(17)) + } + } + + kotlinOptions { + jvmTarget = "17" } buildFeatures { buildConfig = true compose = true } - - kotlinOptions { - jvmTarget = "1.8" - } } dependencies { @@ -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) @@ -76,4 +78,6 @@ dependencies { debugImplementation(libs.androidx.ui.test.manifest) testImplementation(libs.robolectric) + + androidTestImplementation(libs.ui.test.junit4) } \ No newline at end of file diff --git a/places-compose/src/androidTest/java/com/google/android/libraries/places/compose/autocomplete/components/PlacesAutocompleteTextFieldTest.kt b/places-compose/src/androidTest/java/com/google/android/libraries/places/compose/autocomplete/components/PlacesAutocompleteTextFieldTest.kt index d280b37..b33f5e9 100644 --- a/places-compose/src/androidTest/java/com/google/android/libraries/places/compose/autocomplete/components/PlacesAutocompleteTextFieldTest.kt +++ b/places-compose/src/androidTest/java/com/google/android/libraries/places/compose/autocomplete/components/PlacesAutocompleteTextFieldTest.kt @@ -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 = {},