0

I've created a small android app using a Map Fragment and been testing it using jetbrains-studio. I've obtained an API key and it works fine, whether the phone is plugged into the laptop via the USB cable or whether I carry it around standalone (I need to do this as it has a tracking element involved).

I have "Maps SDK for Android" API enabled via the APIs and services dashboard.

When I uploaded the App I went to "App signing" and downloaded the Google certificate, called "deployment_cert.der". When it came time to compile my app,

keytool -importcert -file deployment_cert.der -keystore keystore.jks

(keystore was the file created when I went to compile the release version of the app as a signed apk; when I uploaded the app, Google didn't grumble and accepted it)

I got my wife to test out the app by downloading from the playstore on her phone and tablet but instead of the map, I get a grey box, with the Google logo in the corner, +/- zoom buttons and the "home centre" circle in the top right hand corner. Everything else on the app is working.

I don't have a clue what could be wrong? Could someone please provide some hints? I am stumped as to what to look for.

I've checked device compatibility and all the devices I've used are listed in the device directory as being OK.

My Manifest file is as follows:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mydomain.ge">

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

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


<application
    android:allowBackup="true"
    android:icon="@drawable/gmarkerblank"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">

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

    <activity
        android:name=".GE"
        android:label="@string/title_activity_ge">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>


</application>

My build.gradle file is:

apply plugin: 'com.android.application'

android {
compileSdkVersion 27
defaultConfig {
    applicationId "com.mydomain.ge"
    minSdkVersion 15
    targetSdkVersion 27
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    multiDexEnabled true
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
}

dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.google.android.gms:play-services-maps: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'
//implementation 'com.google.android.gms:play-services:12.0.1'
implementation 'com.android.support:multidex:1.0.3'
implementation 'com.android.support:design:27.1.1'
implementation 'com.github.pengrad:mapscaleview:1.4.1'

}

My activity file is as follows:

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="1"
android:id="@+id/tlll"
>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/llhelpgraphic"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight=".08"
    android:background="#000000"
    android:orientation="horizontal">

    <ImageButton
        android:id="@+id/helpButton"
        android:layout_height="match_parent"
        android:layout_width="wrap_content"
        android:layout_margin="3dp"
        android:adjustViewBounds="true"
        android:src="@drawable/help5"
        />

    <ImageView
        android:id="@+id/titleview"
        android:layout_height="match_parent"
        android:layout_width="fill_parent"
        android:layout_weight="1"
        android:src="@drawable/title"
        />

</LinearLayout>

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/frlayout"
    android:layout_weight=".82"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    >

    <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=".GE" />

</FrameLayout>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight=".10"
    android:background="#004D79"
    android:orientation="horizontal">

    <EditText
        android:id="@+id/addressText"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_marginLeft="10dp"
        android:layout_marginTop="7dp"
        android:layout_weight="1"
        android:background="#FFFFFF"
        android:text="Enter UK address or postcode">
    </EditText>

    <Button
        android:id="@+id/findButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="5dp"
        android:text="Find">
    </Button>
</LinearLayout>

Basically, what this produces is, a top row containing an image button, then next to it, filling up the rest of the row is the title of the app Then below is the map, filling up the most of the space The very bottom is a row containing a text edit box, and a button on the right hand side. I can't see anything obviously amiss in the source code

Paul Lee
  • 25
  • 4

1 Answers1

0

Your app generates different SHA-1 fingerprints depending on your build variant.

Also when you use Google's App Signing, Google generates a SHA-1 fingerprint for you when you upload your apk, so you need to add that fingerprint in your Google Cloud Platform Console like you did with your debug fingerprint.

You can view the generated fingerprint by going to Google Play Console -> Release Management -> App signing

Mohamed Khaled
  • 139
  • 1
  • 7
  • Hi Mohamed, thanks for your comment. I didn't need to apply a certificate for debugging on my phone, but had to do it when compiling to create a release version for upload to the play store. – Paul Lee Feb 02 '19 at 10:37
  • Hi Paul, SHA-1 fingerprint and Keystore and signing certificates are different things. You need to add your generated SHA-1 hash to your Google Maps API key. – Mohamed Khaled Feb 02 '19 at 15:24
  • Hi, Thanks again! Do you know how I do this? The best example is here: https://stackoverflow.com/questions/31834433/google-maps-api-key-in-release-build-doesnt-work But the best top voted answer says "Paste this newly copied SHA-1 fingerprint to Developer Console and map in release mode will show." Which is where I lost it. – Paul Lee Feb 02 '19 at 17:08
  • I think I'm making some headway. I've gone to the Playstore AppSigning page and got the SHA1 certificate "number". I've just realised that the Developer Console was in my google maps console and under "Application restrictions", I've put the number in the relevant box. It saved OK, but didn't issue a new API key number. – Paul Lee Feb 02 '19 at 17:20
  • The Maps API key you put in your Android project, have you restricted that API key in the Developer Console? if so you have to put the SHA-1 you copied from Play console in that API key restriction settings. – Mohamed Khaled Feb 02 '19 at 19:25
  • Thanks my friend, I owe you a big drink, this solved the problem! – Paul Lee Feb 03 '19 at 12:31