I am trying to connect Maps SDK to my application. I have generated api key and restricted it for android, added package name, SHA-1 fingerprint and restricted it to Maps SDK. Bellow are my dependecies and plugins. When I look at logs i can see that application has been connected to the API, permissions have been granted and map has been initialized. At the end I am getting warning
"Unable to update local snapshot for com.google.android.libraries.consentverifier#com.example.travelnotes"
When I go to google cloud and look at Maps SDK API, requests have been made. I have my api key, permissions, package name, google play services version in AndroidManifest.xml. The fragment for maps is defined in activity_google_maps.xml. When I click on button which is supposed to open the maps I get blank screen with color of my backround and when i move two fingers across the screen a compass is shows up in the upper left corner.
Module level build.gradle
plugins {
id 'com.android.application'
id 'com.google.android.libraries.mapsplatform.secrets-gradle-plugin'
id 'com.google.gms.google-services'
}
android {
namespace 'com.example.travelnotes'
compileSdk 33
defaultConfig {
applicationId "com.example.travelnotes"
minSdk 19
targetSdk 33
versionCode 1
versionName "1.1"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'),
'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
buildToolsVersion '33.0.2'
ndkVersion '25.2.9519653'
buildFeatures {
viewBinding true
}
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.google.android.material:material:1.8.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'com.google.android.material:material:1.8.0'
implementation 'com.google.android.gms:play-services-maps:18.1.0'
implementation 'com.google.android.gms:play-services-basement:18.2.0'
implementation platform('com.google.firebase:firebase-bom:31.5.0')
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
}
Project level build.gradle
buildscript {
repositories {
google()
mavenCentral()
}
dependencies {
classpath 'com.google.gms:google-services:4.3.15'
}
}
plugins {
id 'com.android.application' version '7.4.2' apply false
id 'com.android.library' version '7.4.2' apply false
id 'com.google.android.libraries.mapsplatform.secrets-gradle-plugin' version '2.0.1'
apply false}
task clean(type: Delete) {
delete rootProject.buildDir
}
settings.gradle
pluginManagement {
repositories {
gradlePluginPortal()
google()
mavenCentral()
}
}
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
}
}
rootProject.name = "TravelNotes"
include ':app'
activity_google_maps.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.fragment.app.FragmentContainerView
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/map"
tools:context=".GoogleMapActivity"
android:name="com.google.android.gms.maps.SupportMapFragment" />
GoogleMapsActivity.java
package com.example.travelnotes;
import android.Manifest;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapsInitializer;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.CameraPosition;
import com.google.android.gms.maps.model.LatLng;
public class GoogleMapActivity extends AppCompatActivity implements OnMapReadyCallback {
@Override
public void onMapReady(@NonNull GoogleMap googleMap) {
Toast.makeText(this, "Map is Ready", Toast.LENGTH_SHORT).show();
mMap = googleMap;
if (mMap == null){
Log.d(TAG, "map is null");
}
else {
Log.d(TAG, "map is not null");
}
LatLng location = new LatLng(37.7749, -122.4194); // San Francisco
CameraPosition cameraPosition = new CameraPosition.Builder()
.target(location)
.zoom(10) // Zoom level
.build();
googleMap.moveCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
}
private static final String TAG = "GoogleMapActivity";
private Boolean locationPermissionStatus = false;
private static final int locationPermissionRequestCode = 1234;
private GoogleMap mMap;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_google_map);
Log.d(TAG, "Map activity created");
getLocationPermission();
}
private void initializeMap(){
SupportMapFragment supportMapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
assert supportMapFragment != null;
Log.d(TAG, "Map has been initialized");
supportMapFragment.getMapAsync(GoogleMapActivity.this);
}
private void getLocationPermission(){
Log.d(TAG, "location permission will be given");
String[] permissions = {Manifest.permission.ACCESS_FINE_LOCATION,
Manifest.permission.ACCESS_COARSE_LOCATION};
if (ContextCompat.checkSelfPermission(this.getApplicationContext(),
Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED){
Log.d(TAG, "location permission will be given");
if (ContextCompat.checkSelfPermission(this.getApplicationContext(),
Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED){
Log.d(TAG, "location permission granted");
locationPermissionStatus = true;
//initializeMap();
}
else {
ActivityCompat.requestPermissions(this, permissions, locationPermissionRequestCode);
}
}
else {
ActivityCompat.requestPermissions(this, permissions, locationPermissionRequestCode);
}
}
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
//super.onRequestPermissionsResult(requestCode, permissions, grantResults);
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
locationPermissionStatus = false;
Log.d(TAG, "onRequestPermissionsResult");
switch (requestCode) {
case locationPermissionRequestCode: {
if (grantResults.length > 0) {
for (int grantResult : grantResults) {
if (grantResult != PackageManager.PERMISSION_GRANTED) {
Log.d(TAG, "location not granted");
locationPermissionStatus = false;
return;
}
}
Log.d(TAG, "location permission granted true");
locationPermissionStatus = true;
initializeMap();
}
}
}
}
}