How to fix: “ grpc failed” while using Geocoder.getFromLocation

Have you ever seen a crash or error logs like below, when accessing location data in Android.

I Geocoder: Geocoder getFromLocation --- mService = android.location.ILocationManager$Stub$Proxy@4f84fe, ex = grpc failed, return results = []
D AndroidRuntime: Shutting down VM
E AndroidRuntime: FATAL EXCEPTION: main
E AndroidRuntime: Process: com.your.packagename, PID: 19452
E AndroidRuntime: java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
E AndroidRuntime:        at$
E AndroidRuntime:        at
E AndroidRuntime: Caused by: java.lang.reflect.InvocationTargetException
E AndroidRuntime:        at java.lang.reflect.Method.invoke(Native Method)
E AndroidRuntime:        at$
E AndroidRuntime:        ... 1 more
E AndroidRuntime: Caused by: grpc failed
E AndroidRuntime:        at android.location.Geocoder.getFromLocation(

The code used for reverse geodecoding is normally look like as below,

        .addOnSuccessListener { location : Location? ->
            // Got last known location. In some rare situations this can be null.
		mLocation = location
                if (mLocation != null) {

    fun getCompleteReadableAddress() {
        val geocoder = Geocoder(this, Locale.getDefault())
        // Address found using the Geocoder.
        var addresses: List<Address> = emptyList()
        if (mLocation != null) {
            Log.d(TAG,"Last known Latitude :: " + mLocation!!.getLatitude() + " Longitude :: " + mLocation!!.getLongitude()
            addresses = geocoder.getFromLocation(
                // In this sample, we get just a single address.
            if (!addresses.isEmpty()) {
                val address = addresses[0]
                Log.d(TAG, "CompleteReadableAddress: " + address)
                Log.d(TAG, "Admin area " + address.adminArea)

The crash has happened while execution of function “geocoder.getFromLocation” which actually does the reverse geodecoding.

The possible cause of the failure of this function, might be unstable network connectivity which causes the reverse geodecoding failing. As reported in [1] and [2]


  1. Make sure to check you are connected to network using network check API’s of Android
  2. Add “try catch” around “geocoder.getFromLocation” and display error message from “catch” block saying, address decoding failed retry etc.
  3. Use some default values if you are taking some actions based on users fetched address.

References –

Leave a Comment