0

I'm a beginner with AndroidStudio so i tried to build a basic app. I added a GoogleMap activity and it worked well. Then i added Firebase to the app, and i found that GoogleMapActivity wasn't working anymore. It just show me a blank page with the "google" logo on the bottom left. I tried to run the program on a virtual device and on a real one. No success.

I tried to changed the key, I clean/rebuild the app too. The fact is.... the logcat didn't display any message, not even a warning.

I really don't understand why the GoogleMapActivity was working before, and doesn't work anymore.

You have to know that i changed a lot of dependencies when i added Firebase. Maybe it is a problem of SDK versioning ? I don't know...

Here is my permissions in the AndroidManifest.xml :

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

    <!-- To auto-complete the email text field in the login form with the user's emails -->
    <uses-permission android:name="android.permission.GET_ACCOUNTS" />
    <uses-permission android:name="android.permission.READ_PROFILE" />
    <uses-permission android:name="android.permission.READ_CONTACTS" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>


    <permission
        android:name="com.example.mapdemo.permission.MAPS_RECEIVE"
        android:protectionLevel="signature" />
    <uses-permission android:name="com.example.barcodelibrary.permission.MAPS_RECEIVE"/>

<meta-data
    android:name="com.google.android.geo.API_KEY"
    android:value="@string/google_maps_key" />
<meta-data android:name="com.google.android.gms.version"
    android:value="@integer/google_play_services_version" />

Of course, i have a valid Google API key looking like this in the google_maps_api.xml file.

<string name="google_maps_key" templateMergeStrategy="preserve" translatable="false">[i have a real key but i don't know if i can show it here ?]</string>

Here is my build.gradle (module:app) file :

apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'

android {
    compileSdkVersion 28
    defaultConfig {
        applicationId "com.kandel.myandroidapp"
        minSdkVersion 26
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(include: ['*.jar'], dir: 'libs')
    //noinspection GradleCompatible
    implementation 'com.android.support:appcompat-v7:28.0.0-alpha3'
    implementation 'com.android.support.constraint:constraint-layout:1.1.2'
    implementation 'com.android.support:support-annotations:28.0.0-alpha3'
    implementation 'com.google.firebase:firebase-auth:16.0.2'
    implementation 'com.google.firebase:firebase-core:16.0.1'
    implementation 'com.google.firebase:firebase-database:16.0.1'

    implementation 'com.google.android.gms:play-services:12.0.1'
    implementation 'com.google.android.gms:play-services-maps:15.0.1'
    implementation 'com.google.android.gms:play-services-auth:15.0.1'
    implementation 'com.google.android.gms:play-services-identity:15.0.1'

    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

EDIT1 : Adding my GoogleMapActivity code

As you can see, it is the basic activity provided by AndroidStudio. Do i miss something ?

package com.kandel.myandroidapp;

import android.support.v4.app.FragmentActivity;
import android.os.Bundle;

import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;

public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {

    private GoogleMap mMap;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_maps);
        // Obtain the SupportMapFragment and get notified when the map is ready to be used.
        SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
                .findFragmentById(R.id.map);
        mapFragment.getMapAsync(this);
    }


    /**
     * Manipulates the map once available.
     * This callback is triggered when the map is ready to be used.
     * This is where we can add markers or lines, add listeners or move the camera. In this case,
     * we just add a marker near Sydney, Australia.
     * If Google Play services is not installed on the device, the user will be prompted to install
     * it inside the SupportMapFragment. This method will only be triggered once the user has
     * installed Google Play services and returned to the app.
     */
    @Override
    public void onMapReady(GoogleMap googleMap) {
        mMap = googleMap;

        // Add a marker in Sydney and move the camera
        LatLng sydney = new LatLng(-34, 151);
        mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
        mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
    }
}

EDIT 2 : Adding my Activity_maps.xml file

<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:map="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/map"
    android:name="com.google.android.gms.maps.SupportMapFragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MapsActivity" />
Ikunn
  • 1
  • 5

3 Answers3

0

When you add firebase you have to add its google-services.json to project. The google map use the key inside that file after adding firebase to project

masoud vali
  • 1,382
  • 2
  • 14
  • 28
  • I already add it. Firebase is working well, that's not the point. The problem is about GoogleMap – Ikunn Jul 21 '18 at 05:19
  • @HugoKandel ok. maybe that's because of ` implementation 'com.google.android.gms:play-services:12.0.1'` use 15.0.1 instead of 12.0.1 version – masoud vali Jul 21 '18 at 05:25
  • Yes, it's because 12.0.1 is the "highest" version possible. The 15.0.1 version of "play-service" doesn't exist. It is different from **play-services-map**, which had a 15.0.1 – Ikunn Jul 21 '18 at 05:48
  • Can you explain why you need the play-services because when you add it's childs you don't need to add the core library – masoud vali Jul 21 '18 at 06:12
  • @MRah I edit the post with my GoogleMapActivity.java file. – Ikunn Jul 21 '18 at 06:31
  • @masoudvali I keep the play-services because i used it before, but i already noticed that it's not necessary anymore. I tried with it, without it, only with the first, only with play-services-maps.... No success. – Ikunn Jul 21 '18 at 06:31
  • try generating new key on google developer console and add it to your project – masoud vali Jul 21 '18 at 06:43
  • @HugoKandel is google play services available in the emulator or device you are testing? – MRah Jul 21 '18 at 18:48
  • Yep. As i said, the GoogleMapActivity worked before i tried to install Firebase. – Ikunn Jul 23 '18 at 06:15
0

add this in your manifest file

 ` <meta-data
            android:name="com.google.android.geo.API_KEY"
            android:value="Your Api key" />`

for more detail visit google map api

0

You should add your SHA-1 fingerprint while generating a key , you will get it from your android studio or from the command line. You can go through the following link to generate it and use it while generating the key of the map.

SHA-1 fingerprint of keystore certificate

steps to generate it using android studio :

  1. Go to the gradle file on the right side of android studio.
  2. Expand your project
  3. Go to app folder and click on android
  4. Select the signing report to generate it. 5)You can find it in the Run space at the bottom with a keyword of SHA1
Avi
  • 3,075
  • 8
  • 17
  • 27