Geocoder grpc failed

Mackan picture Mackan · Aug 5, 2017 · Viewed 12.5k times · Source

Last month of so geocoder has started to fail every time with "grpc failed" error and I can't seem to be able to solve it. I've looked at java.io.IOException: grpc failed but it didn't really solve the problem.

For exampel the code

Geocoder geocoder = new Geocoder(context, Locale.getDefault());
addresses = geocoder.getFromLocation(lat, lng, 1); // Here if fails with "grpc failed"

I've had the same code for years, but it's just lately it has stopped working when I recompile the app and test on an emulator or real device.

If I compile against SDK 25, using build tool 25 it works on an emulator with SDK 25. But if I try on an emulator with SDK 24, 26 or any other SDK version, it will fail with "grpc failed". I've tried to create a new virtual device etc. but same problem.

I have no clue how to fix it and what the problem is.

Current setup: targetSDK/compileSDK 25, build tool 25.0.3, Android Studio 2.3.3, regular emulator. (I've tried other build tools and SDK versions, but problem still remains)

Any ideas?

Answer

Cifus picture Cifus · Oct 4, 2017

The problem may be that you are trying to use Geocoder in the main thread, if you are using an IntentService you have this URL option to create in another process although you can always use an Asynctask or similar.