Problem with Google Maps when I create .apk

0

I'm creating an Android app that uses the Google Maps API. But I'm having problems when I create .apk and install it on my phone, giving this error:

09-18 16:05:07.631  18129-18238/com.anderson.app E/Google Maps Android API﹕ Failed to load map. Error contacting Google servers. This is probably an authentication issue (but could be due to network errors).

But if I run running directly through Android Studio the phone is working perfectly.

NOTE: When I created SHA1 to put it on google console I did so:

keytool -list -keystore C:\Users\Anderson\AndroidStudioProjects\Lisandro\android.jks

Does this serve both debug and release?

More information ...

build.gradle

apply plugin: 'com.android.application'

android {
    signingConfigs {
        android {
            keyAlias 'android'
            keyPassword 'android'
            storeFile file('C:/Users/Anderson/AndroidStudioProjects/Lisandro/android.jks')
            storePassword 'android'
        }
    }
    compileSdkVersion 'Google Inc.:Google APIs:19'
    buildToolsVersion '20.0.0'
    defaultConfig {
        applicationId 'com.anderson.lisandro'
        minSdkVersion 14
        targetSdkVersion 19
        versionCode 1
        versionName '1.0'
    }
    buildTypes {
        release {
            runProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            signingConfig signingConfigs.android
            debuggable false
            jniDebugBuild false
        }
        debug {
            signingConfig signingConfigs.android
        }
    }
    productFlavors {
    }
}

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

AndroidManifest.xml

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

    <uses-permission android:name="android.permission.INTERNET" />
    <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" />
    <!--\
         The ACCESS_COARSE/FINE_LOCATION permissions are not required to use
         Google Maps Android API v2, but are recommended.
    -->
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".MapsActivity"
            android:label="@string/title_activity_maps" >
            <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.maps.v2.API_KEY"
            android:value="AIzaSyA1ad9...lO5pAoidaVA" />
    </application>


</manifest>

Google Console data

That's all! kkk

Has anyone ever been through this?

Thank you!

    
asked by anonymous 17.09.2014 / 22:00

1 answer

0

The solution found for the problem, during several attempts of possible errors, is to use the same certificate whenever possible for all builds .

If this is not possible or desired, you must register each certificate (either one for release , another for debug or whatever criteria used) with the < in the Public API section of the project in Google Developers Console .

This is also important if you are using Gradle's flavors , where final apk will have a suffix or prefix in the package name.

To generate the fingerprint simply use:

keytool -list -v -keystore mystore.keystore

In this specific case:

When you tested your app in debug mode, you were using a key for build debug that had access registered in the Google console.

But when you were to generate your apk in build release you were using another certificate, which was not in the Google console, which caused the authentication problem.

    
19.09.2014 / 06:03