Problem with Google Maps when creating . apk

Asked

Viewed 747 times

0

I’m creating an app for Android that uses the Google Maps API. Just that I’m having problems when I create the . apk and install on mobile, is 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 straight by Android Studio for mobile 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

This is for both debug and release?

Some 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>

Data from Google Console

inserir a descrição da imagem aqui

That is all! kkk

Someone’s been through it?

Thank you!

  • When I spin by. apk from the following error: 09-18 12:03:23.691 13868-14048/com.anderson.app I/Google Maps Android API Failed to contact Google Servers. Another Attempt will be made when Connectivity is established. 09-18 12:03:23.691 13868-14048/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). When I run straight through Android Studio it works normally. but when I Gero the . apk gives this error there, why it will be?

  • Dude, check out the name of your package in Android Studio. When I went to implement Google Maps, I got A LOT and after a lot of pain I paid attention that the generated package is com.seupackage.debug. I added . debug to the console and it worked great. Check this point! IMPORTANT DETAIL: Fully uninstall the mobile app/emulator before testing

  • But in debug mode works perfectly, the problem is when I Gero . apk

  • @Andersonsouza, if you can, put your build.gradle (mischaracterising sensitive data) and the AndroidManifest also.

  • Anderson, I see you wear two keystore's different... Within the build.gradle is using the android.jks and in the keytool is using the debug.keystore. Do these files have the same content? To test the exchange, you need to erase the data from the app!!

  • I don’t know... kkk android.jks is the same thing as debug.Keystore? Can I use keytool with android.jks?

  • 1

    It’s not the same thing no, only if the content is the same. Take a look, but you should use the same keystore, in case the debug.keystore in both places. Use the debug.keystore because you’ve already set it up in Developer Console, change what is in build.gradle.

  • Cara regerei a chave utilizando o android.jks: keytool -list -Keystore C: Users Anderson Androidstudioproject s Lisandro android.jks Fui la no google console e gerei outra chave, pus na aplicação, uninstalei tudo no celular, installed again and follows the same problem! ;/

  • It didn’t, it’s giving the same problem!

  • I’m running out of ideas, I’ll see this later calmly, I’m leaving now. But try to update the version of your dependency on google play services for com.google.android.gms:play-services:5.+ as in the documentation: http://developer.android.com/google/play-services/setup.html. Add the rules of the Proguard even if you’re not using it yet (runProguard false).

  • Cara worked!!! Thank you so much for your dedication and commitment to wanting to help me! Thanks so much! Thank you so much!

  • 2

    The solution was: When using the keytool to generate the key and put it there in google console, use the same key in the build.Gradle of your application. ball show!

  • @Andersonsouza, I put an explanation as an answer in case anyone comes across this problem. If there is something missing about the final solution you can edit or suggest some change.

Show 8 more comments

1 answer

0


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

If this is not possible or desired, you need to register each certificate (be one for release, another to debug or whatever criterion is used) with the pair: <fingerprint certificate*>:<name.do.package> in the section Public API of the project in Google Developers Console.

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

To generate the fingerprint just use:

keytool -list -v -keystore mystore.keystore

In that particular case:

When testing your app in mode debug, was using a key to the build debug that had registered access on the Google console.

But when he was going to spawn his apk in the build release was using another certificate, which was not on the Google console, which caused the authentication problem.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.