'Netty gRPC server on Android - channel not registered to an event loop

When running Netty gRPC server on Android I am getting the following exception

java.lang.IllegalStateException: channel not registered to an event loop

Dependencies that I use:

implementation 'io.grpc:grpc-kotlin-stub:1.2.0'
implementation 'io.grpc:grpc-netty-shaded:1.40.1'
implementation 'io.grpc:grpc-stub:1.40.1'
implementation 'io.grpc:grpc-protobuf-lite:1.40.1'
implementation 'io.grpc:grpc-okhttp:1.40.1'
implementation 'com.google.protobuf:protobuf-kotlin-lite:3.18.1'

Initializing gRPC server like that:

NettyServerBuilder.forPort(7001)
    .addService(Service())
    .build()
    .start()


Solution 1:[1]

Turns out that the exception message was misleading and I was missing network permission in my AndroidManifest file:

<uses-permission android:name="android.permission.INTERNET" />

Solution 2:[2]

You need to add these lines to your AndroidManifest.xml to grant network permission.

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

Also it might be required to uninstall the app/.apk file from the phone/emulator to update the permission cache.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Dmitry Zaytsev
Solution 2 BloodEko