I added a key from another test project to a main. Then I opened https://console.developers.google.com/ and added that key with a new application name (like Linh Dao wrote), but it didn't help.
Then I added a new activity (a template "Google Maps Activity" in a gallery) and opened a file google_maps_api.xml
. From there I again found a link like https://console.developers.google.com/flows/enableapi?apiid=maps_android_backend&keyType=CLIENT_SIDE_ANDROID&r=06:F2:F4:CD...applicationName.
I opened app/build.gradle
, found applicationId
value with applicationIdSuffix
, if exists, and joined, for instance into com.example.myapp.debug
. In the link I changed an applicationName to this new value and opened the link.
Again created a new project, generated a new key and edited it, wrote package name and SHA-1 fingerprint, like @Linh Dao wrote. Then saved. If you later with to find that key, find your project in Google console and open credentials.
I deleted an unnecessary map activity and in AndroidManifest
retained
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="@string/google_maps_key" />
in application
tag.
UPDATE
After several months I got the same exception in debug
build. As I understood, I set wrong API key.
In LogCat I saw this exception:
Then I opened https://console.developers.google.com/, a needed project was opened, clicked on "Maps SDK for Android".
Turn to "Credentials" tab (you can also see https://developers.google.com/maps/documentation/android-sdk/signup for information). Click your API Key.
On the API key
page, under Key restrictions
, set the Application restrictions
. Click + Add package name and fingerprint
.
Enter your package name from LogCat above (for example, com.your_package.debug). Enter your fingerprint from LogCat (91:D6:...:F7). Save it.
As @Ahamed Rasheed wrote, I invalidated caches, cleaned and rebuilt the project.
Clean Project
! It solved my problem after changing API key. – salmanseifian