The provided API key is invalid using Google Places

I am trying to implement the Google Places API in an android app but I get the following exception.

 W/System.err: java.util.concurrent.ExecutionException: com.google.android.gms.common.api.ApiException: 9011: The provided API key is invalid.
    W/System.err:     at com.google.android.gms.tasks.Tasks.zzb(Unknown Source:61)
    W/System.err:     at com.google.android.gms.tasks.Tasks.await(Unknown Source:33)
            at com.example.smartorders.PlaceAutoCompleteAdapter.getPredictions(PlaceAutoCompleteAdapter.java:128)
            at com.example.smartorders.PlaceAutoCompleteAdapter.access$100(PlaceAutoCompleteAdapter.java:42)
            at com.example.smartorders.PlaceAutoCompleteAdapter$1.performFiltering(PlaceAutoCompleteAdapter.java:80)
            at android.widget.Filter$RequestHandler.handleMessage(Filter.java:234)
            at android.os.Handler.dispatchMessage(Handler.java:105)
            at android.os.Looper.loop(Looper.java:164)
            at android.os.HandlerThread.run(HandlerThread.java:65)
        Caused by: com.google.android.gms.common.api.ApiException: 9011: The provided API key is invalid.
    W/System.err:     at com.google.android.libraries.places.internal.zzbo.zza(com.google.android.libraries.places:places@@2.2.0:5)
            at com.google.android.libraries.places.internal.zzby.then(com.google.android.libraries.places:places@@2.2.0:2)
            at com.google.android.gms.tasks.zzd.run(Unknown Source:5)
            at android.os.Handler.handleCallback(Handler.java:789)
            at android.os.Handler.dispatchMessage(Handler.java:98)
            at android.os.Looper.loop(Looper.java:164)
            at android.app.ActivityThread.main(ActivityThread.java:6541)
            at java.lang.reflect.Method.invoke(Native Method)
            at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)

I have double-checked that billing is enabled in my account. I have created the SHA1 code and restricted the android app and added the API Places. I have created a second key and did all the above but still no luck. I have followed this example: How to implement google places autocomplete programmatically

Any ideas on how to fix this issue?

Answer

play-services-places:17.0.0 places dependency is deprecated

implementation 'com.google.android.gms:play-services-places:17.0.0'

changes to

`implementation 'com.google.android.libraries.places:places:2.2.0'`

please this one this there is a full example of AutoComplete enter image description here

Click Create credential -> API Key. You will get an API key. Now enable google places API and put your API key in your project. You will get the result

Source: stackoverflow
The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 .