Here is one simplest possible example of google maps.
First start new "Empty Views Activity" like I already explained
here
In "\GoogleMapsTestSandBox\app\build.gradle.kts" I have added "com.google.android.gms:play-services-maps:19.2.0", so my dependencies looks like
dependencies {
implementation(libs.androidx.core.ktx)
implementation(libs.androidx.appcompat)
implementation(libs.material)
implementation(libs.androidx.activity)
implementation(libs.androidx.constraintlayout)
testImplementation(libs.junit)
androidTestImplementation(libs.androidx.junit)
androidTestImplementation(libs.androidx.espresso.core)
implementation("com.google.android.gms:play-services-maps:19.2.0")
}
Since I don't want to make google maps key public, I will add "secrets" file. To do it, first I wil add id("com.google.android.libraries.mapsplatform.secrets-gradle-plugin") version "2.0.1" plugin in gradle "\GoogleMapsTestSandBox\app\build.gradle.kts":
plugins {
alias(libs.plugins.android.application)
alias(libs.plugins.kotlin.android)
id("com.google.android.libraries.mapsplatform.secrets-gradle-plugin") version "2.0.1"
}
Before I sync my gradle, I need to add two files local.defaults.properties and secrets.properties.
local.defaults.properties:
MAPS_API_KEY=DEFAULT_API_KEY
secrets.properties:
sdk.dir=C\:\\Users\\smilosev\\AppData\\Local\\Android\\Sdk
MAPS_API_KEY=myMapsApiKey;
Now in "\GoogleMapsTestSandBox\app\src\main\AndroidManifest.xml" add:
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="${MAPS_API_KEY}" />
Since in this example I just want to display google maps my "\GoogleMapsTestSandBox\app\src\main\res\layout\activity_main.xml" will look like:
<fragment
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
For this, simplest example my "\GoogleMapsTestSandBox\app\src\main\java\com\milosev\googlemapstestsandbox\MainActivity.kt" will look like:
package com.milosev.googlemapstestsandbox
import android.os.Bundle
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
enableEdgeToEdge()
setContentView(R.layout.activity_main)
}
}
Example download from
here.