Codemator Codemator - 8 days ago 6
Android Question

Android: Google Maps is visible on Simulator not on Phone

Hi I have built a small android application based on following documentation
https://developer.android.com/training/location/retrieve-current.html

I have used the Maps Activity. It will just show current location marker and a Toast which will show the current latitude and longitude

It is working perfectly fine on Android Emulator. But when I Installed the signed apk on my android phone, the map is not visible, even though it Toasts the location details

On Phone

Android Phone

Answer

I have followed following steps to resolve the issue

I had already created a keystore file following this documentation. Now I have to use SHA1 Fingerprint of my keystore file in the API to restrict it (For security reasons for release version this is mandatory)

1) Run Key Tool Command in the Keytool.exe file location as below C:\Users{USERNAME}.AndroidStudio2.2\system\restart\jre\bin>

keytool -list -v -keystore {File path for Keystore you have created durning Signing}

This will prompt for password and once you enter the password, it will give SHA1 Fingerprint

2) Now Go to Google API Manager Console (https://console.developers.google.com/apis) and select your MAP API

In Key restricion Field Select "Android Application"

Enter the Package name of your application and enter the SHA1 Finger Print you have recieved and save

3) Since we are creating the release version, Enter the API Key in your google_maps_api.xml from the release folder (app\src\release\res\valies\google_maps_api.xml)

4) Now Go to your builld.gradle file and create a new sectction signingConfigs under android

android {

signingConfigs {
        config {
            keyAlias '{KeyAlias}'
            keyPassword '{password}'
            storeFile file('{Path of keystore file eg: c:/keystore.jks'})
            storePassword '{Store password}'
        }
    }

} Also refer these values in debug node and release node

buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        signingConfig signingConfigs.config
    }
    debug {
        signingConfig signingConfigs.config
    }
}

4) Create Signed APK