ProviderNotFoundException: No functional server found. Try adding a dependency on the grpc-netty or grpc-netty-shaded artifact
测试老版本io.grpc:grpc-netty:1.1.2,用Server server = ServerBuilder.forPort(port)是正常的。使用新版本io.grpc:grpc-netty:1.42.1 ,必须得用NettyServerBuilder。否则就报上面的错。但JAVA正常,奇怪不。
private void startServer(int port){ try { Server server = NettyServerBuilder.forPort(port) .addService(new GreeterImpl()) .build() .start(); Log.d("TAG","Server started, listening on " + port); } catch (IOException e) { e.printStackTrace(); Log.d("TAG", e.getMessage()); } }
apply plugin: 'com.android.application' apply plugin: 'com.google.protobuf' android { compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 } compileSdkVersion 27 defaultConfig { applicationId "io.grpc.helloworldexample" minSdkVersion 21 targetSdkVersion 27 versionCode 1 versionName "1.0" } buildTypes { debug { minifyEnabled false } release { minifyEnabled true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } lintOptions { disable 'GoogleAppIndexingWarning', 'HardcodedText', 'InvalidPackage' textReport true textOutput "stdout" } configurations.all { resolutionStrategy.force 'com.google.code.findbugs:jsr305:3.0.1' } packagingOptions { pickFirst 'meta-INF/INDEX.LIST' pickFirst 'meta-INF/LICENSE' pickFirst 'meta-INF/io.netty.versions.properties' } protobuf { protoc { artifact = 'com.google.protobuf:protoc:3.17.2' } plugins { grpc { artifact = 'io.grpc:protoc-gen-grpc-java:1.42.0' // CURRENT_GRPC_VERSION } } generateProtoTasks { all().each { task -> task.builtins { java { option 'lite' } } task.plugins { grpc { // Options added to --grpc_out option 'lite' } } } } } } dependencies { implementation 'com.android.support:appcompat-v7:27.0.2' // You need to build grpc-java to obtain these libraries below. implementation 'io.grpc:grpc-netty:1.42.1' // CURRENT_GRPC_VERSION implementation 'io.grpc:grpc-protobuf:1.42.0' // CURRENT_GRPC_VERSION implementation 'io.grpc:grpc-stub:1.42.0' // CURRENT_GRPC_VERSION implementation 'org.apache.tomcat:annotations-api:6.0.53' }
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)