1

I am using the Google API in my application, but can only get the debug ssh to work the with Google API. I have a keystore that I sign with, I've done the same with previous apps in the past and have had no problem. I've also enabled all the API's. I'm signing my app with a release apk. I'm using the SSH1 from that release apk in the SSH1 for the Google API credential. I'm using the Key from Google in my application. I've read all all stack overflow and google docs on this, and have tried pretty much everything, but I cannot get it to work. It only works when I am debugging my app (in which case I use the SSH1 generated by the debug keystore and the Key that I use with that SSH1). However, when I sign with my person release keystore and publish on Beta on the app store and download onto my phone, I get the error that my API key is invalid. Here are my manifest and build files as well as my layout file if that helps. Thank you.

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

    <permission android:name="com.dev.cromer.jason.whatsappening.permission.MAPS_RECEIVE" android:protectionLevel="signature" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="com.dev.cromer.jason.whatsappening.permission.MAPS_RECEIVE" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />

    <uses-feature
        android:glEsVersion="0x00020000"
        android:required="true" />

    <application
        android:allowBackup="true"
        android:fullBackupContent="true"
        android:icon="@drawable/icon_logo"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".activities.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

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

        <activity
            android:name=".activities.MapActivity"
            android:label="@string/app_name" >
        </activity>
        <activity
            android:name=".activities.SetMarkerTitleActivity"
            android:label="@string/app_name" >
        </activity>
        <activity
            android:name=".activities.SearchPlaceActivity"
            android:label="@string/app_name" >
        </activity>
        <activity
            android:name=".activities.SetMarkerDescriptionActivity"
            android:label="@string/app_name" >
        </activity>
        <activity
            android:name=".activities.MarkerDescriptionActivity"
            android:label="@string/app_name" >
        </activity>
    </application>

</manifest>

Here is my build:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "22.0.1"

    defaultConfig {
        applicationId "com.dev.cromer.jason.whatsappening"
        minSdkVersion 15
        targetSdkVersion 23
        versionCode 12
        versionName "1.012"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:appcompat-v7:23.0.0'
    compile 'com.google.android.gms:play-services:7.8.0'
}

and my layout:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:theme="@style/AppTheme">

    <fragment xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/map"
        tools:context="com.dev.cromer.jason.whatsappening.activities.MapActivity"
        android:name="com.google.android.gms.maps.SupportMapFragment">
    </fragment>


    <EditText
        android:id="@+id/searchBarEditText"
        android:layout_width="250dp"
        android:layout_height="wrap_content"
        android:background="@drawable/textview_border"
        android:alpha=".8"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="10dp"
        android:hint="@string/search_bar_hint"
        android:singleLine="true"
        android:textColor="#000000"
        android:padding="8dp" />


    <ImageView
        android:id="@+id/poweredBy"
        android:contentDescription="@string/powered_by_google_image"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/powered_by_google_light"
        android:layout_alignParentBottom="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true" />

</RelativeLayout>
Jason Cromer
  • 1,468
  • 3
  • 11
  • 21
  • try http://stackoverflow.com/a/19627394/5202007 – Mohammad Tauqir Sep 13 '15 at 05:25
  • For generating SHA1 to get **Google API Key** you have to use signed apk certificate. – Pankaj Sep 13 '15 at 05:26
  • @Clairvoyant, I know, I've done this several times before with my other apps. I'm using a signed apk certificate. I'm using the SHA1 from my signed certificate in the Google API credentials section, and the Google API Key that corresponds to that SHA1 in my app. So it should be working, but its not. It only works if I'm in debug mode with my debug SHA1. – Jason Cromer Sep 13 '15 at 14:39
  • @Tauqir, I'm using this in my android app, why would I use a browser key? – Jason Cromer Sep 13 '15 at 14:40
  • @Jason, You'll find option for Android Key in drop down. – Mohammad Tauqir Sep 14 '15 at 06:15

1 Answers1

2

UPDATE:

It turns out I had my API key stored in a resource xml file under the debug directory of my project. I needed to put it either in my project or release directory, then specify that string in my Manifest file instead of the one under the debug directory. This was the issue that I was having. Thank you those you commented for your time.

Jason Cromer
  • 1,468
  • 3
  • 11
  • 21