GoogleCloudPlatform / android-docs-samples

Apache License 2.0
375 stars 596 forks source link

Speech Sample: Error calling the API, io.grpc.StatusRuntimeException: UNAVAILABLE on Android 4.4.4 #61

Closed zznam closed 6 years ago

zznam commented 6 years ago

Can't run this sample on android 4.4.4 This error appears:

03-21 17:59:27.728 17869-27213/com.testgoogle E/SpeechService: Error calling the API. io.grpc.StatusRuntimeException: UNAVAILABLE at io.grpc.Status.asRuntimeException(Status.java:543) at io.grpc.stub.ClientCalls$StreamObserverToCallListenerAdapter.onClose(ClientCalls.java:395) at io.grpc.internal.ClientCallImpl.closeObserver(ClientCallImpl.java:426) at io.grpc.internal.ClientCallImpl.access$100(ClientCallImpl.java:76) at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl.close(ClientCallImpl.java:512) at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl.access$700(ClientCallImpl.java:429) at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl$1StreamClosed.runInContext(ClientCallImpl.java:544) at io.grpc.internal.ContextRunnable.run(ContextRunnable.java:52) at io.grpc.internal.SerializingExecutor.run(SerializingExecutor.java:117) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587) at java.lang.Thread.run(Thread.java:841) Caused by: java.net.ConnectException: failed to connect to speech.googleapis.com/2404:6800:4005:809::200a (port 443): connect failed: ENETUNREACH (Network is unreachable) at libcore.io.IoBridge.connect(IoBridge.java:114) at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:192) at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172) at java.net.Socket.startupSocket(Socket.java:566) at java.net.Socket.(Socket.java:226) at io.grpc.okhttp.OkHttpClientTransport$1.run(OkHttpClientTransport.java:427) at io.grpc.internal.SerializingExecutor.run(SerializingExecutor.java:117)  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)  at java.lang.Thread.run(Thread.java:841)  Caused by: libcore.io.ErrnoException: connect failed: ENETUNREACH (Network is unreachable) at libcore.io.Posix.connect(Native Method) at libcore.io.BlockGuardOs.connect(BlockGuardOs.java:85) at libcore.io.IoBridge.connectErrno(IoBridge.java:127) at libcore.io.IoBridge.connect(IoBridge.java:112) at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:192)  at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)  at java.net.Socket.startupSocket(Socket.java:566)  at java.net.Socket.(Socket.java:226)  at io.grpc.okhttp.OkHttpClientTransport$1.run(OkHttpClientTransport.java:427)  at io.grpc.internal.SerializingExecutor.run(SerializingExecutor.java:117)  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)  at java.lang.Thread.run(Thread.java:841) 

Kreals commented 6 years ago

Also cant run this on android 4.4.4, exactly the same stack-trace. Wondering if it has anything to do with the SSL issues in android 4.4.4.

zznam commented 6 years ago

I found a solution from this project https://github.com/yurifariasg/android-google-speech-sample `

            // Required to support Android 4.x.x (patches for OpenSSL from Google-Play-Services)
            try {
                ProviderInstaller.installIfNeeded(getApplicationContext());
            } catch (GooglePlayServicesRepairableException e) {

                // Indicates that Google Play services is out of date, disabled, etc.
                e.printStackTrace();
                // Prompt the user to install/update/enable Google Play services.
                GooglePlayServicesUtil.showErrorNotification(
                        e.getConnectionStatusCode(), getApplicationContext());
                return;

            } catch (GooglePlayServicesNotAvailableException e) {
                // Indicates a non-recoverable error; the ProviderInstaller is not able
                // to install an up-to-date Provider.
                e.printStackTrace();
                return;

}`

Kreals commented 6 years ago

Yeah i came across that, unfortunately i'm working on a robot that makes it awkward to install google play services. The app isn't really intended for the general phone market. I've injecting my own socket factory to replace the one used by okhttp for the api calls but no joy. I had similar problems connecting to my server via the robot but managed to fix them with the custom socket factory. I'll keep plugging away. You've increased the probability that this is indeed related to the SSL problems so that should help to narrow down a solution. Thanks.