3
votes

I tried to test Google Maps and created a new project, got API key from API console. Everything was working, no problems. But when I tried to add Google Maps activity in to the working project, by making this activity as a luncher, with above steps, now I am getting the following errors:

Google Maps Android API: Authorization failure. Please see https://developers.google.com/maps/documentation/android-api/start for how to correctly set up the map. E/Google Maps Android API: In the Google Developer Console (https://console.developers.google.com) Ensure that the "Google Maps Android API v2" is enabled. Ensure that the following Android Key exists: API Key: AIzaSyA5iBkfmlihtkh2Xc6T61v109eFJ3OGZrE Android Application (;):

AndroidManifest.xml

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

    <!--
         The ACCESS_COARSE/FINE_LOCATION permissions are not required to use
         Google Maps Android API v2, but you must specify either coarse or fine
         location permissions for the 'MyLocation' functionality. 
    -->
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

    <application
        android:name=".AfexApp"
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        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>
        <activity
            android:name=".activities.LoginActivity"
            android:label="Tizimga kirish" />
        <activity
            android:name=".activities.RegistrationActivity"
            android:label="Ro&apos;yxatdan o&apos;tish" />
        <activity android:name=".activities.Tovar_description_Activity" />
        <activity android:name=".activities.OmborActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
            </intent-filter>
        </activity>
        <activity android:name=".models.Switch_Mode" />
        <activity android:name=".activities.SettingActivity" />
        <activity
            android:name=".AddressActivity"
            android:label="@string/title_activity_address"
            android:theme="@style/AppTheme" />
        <activity android:name=".AddressAddingActivity" />
        <!--
             The API key for Google Maps-based APIs is defined as a string resource.
             (See the file "res/values/google_maps_api.xml").
             Note that the API key is linked to the encryption key used to sign the APK.
             You need a different API key for each encryption key, including the release key that is used to
             sign the APK for publishing.
             You can define the keys for the debug and release targets in src/debug/ and src/release/. 
        -->
        <meta-data
            android:name="com.google.android.geo.API_KEY"
            android:value="@string/google_maps_key" />

        <activity
            android:name=".activities.GoogleMapActivity"
            android:label="@string/title_activity_google_map">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

</manifest>
2
@tahsinRupam thanks, but I've already read it and did all steps. It did not help me - Турсунбой Тожиев
Double check Android app restriction on the API key. Is package name and SHA1 correct? - xomena
@xomena All things are correct - Турсунбой Тожиев

2 Answers

1
votes

Enable the Maps API in Google Developers Console (https://console.developers.google.com/).

0
votes

That is because you made a project with map activity but you are trying to add the activity into another project.

You probably used the package name of map activity project in the Maps API in Google Developers Console.

The solution is, create a new map api key with your actual project's package name then use the API key to your project.