GoogleCloud PubSub NoSuchMethodError:没有虚拟方法shouldDiscardUnkownFields

时间:2018-06-08 18:05:03

标签: android google-cloud-pubsub

Desde Android deseo descargar mensajes almacenados en el modulo PubSub de Google Cloud,en el momento de estar realizando el pull se recibe el siguiente error en tiempo de ejecucion:

Android GoogleCloud PubSub NoSuchMethodError: No virtual method shouldDiscardUnkownFields )Z in class Lcom/google/protobuf/CodedInputStream;

El programa usa protobuf,dentrodelcódigodeCodeInputStream esta funcion tiene la forma:

 final boolean shouldDiscardUnknownFields()

¿Porque internamente las dependdencias y el codigo buscan una funcion“virtual”cuando esta definida como“final”?¿que esta pasando?

La funcion donde ocurre el error es este,usando AsyncTask:

    @Override
    protected Integer doInBackground(String...params){
        try{


            Log.d(TAG, "Leyendo archivo de credenciales: "+MainActivity.CREDENTIALS_FILE);
            AssetManager am = context.getAssets();
            InputStream isCredentials =   am.open(MainActivity.CREDENTIALS_FILE);
            ManagedChannel channelImpl = OkHttpChannelBuilder.forAddress("pubsub.googleapis.com",443).negotiationType(NegotiationType.TLS).build();

            Log.d(TAG, "Canal Terminado?:"+ channelImpl.isTerminated());

            GoogleCredentials credential = GoogleCredentials.fromStream(isCredentials);
            credential = credential.createScoped(Arrays.asList("https://www.googleapis.com/auth/pubsub"));


            ExecutorService executor = Executors.newSingleThreadExecutor();
            ClientAuthInterceptor interceptor = new ClientAuthInterceptor(credential, executor);
            Log.d(TAG, "Interceptor: " + interceptor.toString());

            Channel channel = ClientInterceptors.intercept(channelImpl, interceptor);
            Log.d(TAG, "Channel authority: " + channel.authority());


            SubscriberGrpc.SubscriberBlockingStub subscriberStub =  SubscriberGrpc.newBlockingStub(channel);
            PullRequest pullRequest = PullRequest.newBuilder()
                .setSubscription( MainActivity.SUBSCRIPTION )
                .setReturnImmediately( true )
                .setMaxMessages(10)
                .build();

            PullResponse pullResponse = subscriberStub.pull(pullRequest);

            numMessages = pullResponse.getReceivedMessagesCount();
            Log.d(TAG, "Number of messages received: " + String.valueOf(numMessages));
            for (ReceivedMessage message1 :  pullResponse.getReceivedMessagesList()) {
                PubsubMessage pubsubMessage1 = message1.getMessage();
                arrayList.add(pubsubMessage1.toString());
                Log.d(TAG, "Message received (ID="+message1.getAckId()+"): " + pubsubMessage1.toString());
            }

        }catch (IOException e){
            Log.d(TAG, "Excepcion: "+e.toString());
        }
        return 0;
    }

El error ocurre en la linea

 PullResponse pullResponse = subscriberStub.pull(pullRequest);

Este es el gradle

apply plugin: 'com.android.application'
apply plugin: 'com.google.protobuf'

android {
    compileSdkVersion 26
    defaultConfig {
        applicationId "com.example.arkmind_2.googlecloud"
        minSdkVersion 25
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner  "android.support.test.runner.AndroidJUnitRunner"
        multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    lintOptions {
        disable 'InvalidPackage', 'HardcodedText'
    }

    configurations.all {
        resolutionStrategy.force 'com.google.code.findbugs:jsr305:1.3.9'
    }
}

sourceSets {
    main.java.srcDirs += "${protobuf.generatedFilesBaseDir}/main/javalite"
}


dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:26.1.0'
    implementation 'com.android.support.constraint:constraint-layout:1.1.0'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'com.android.support.test:runner:1.0.2'
    androidTestImplementation    'com.android.support.test.espresso:espresso-core:3.0.2'
    implementation 'com.android.support:support-annotations:27.1.1'
    compile 'com.google.protobuf:protobuf-java:3.5.1'
    compile 'io.grpc:grpc-okhttp:1.12.0' // CURRENT_GRPC_VERSION
    compile 'io.grpc:grpc-protobuf-lite:1.12.0' // CURRENT_GRPC_VERSION
    compile 'io.grpc:grpc-stub:1.12.0' // CURRENT_GRPC_VERSION
    compile 'io.grpc:grpc-testing:1.12.0' // CURRENT_GRPC_VERSION
    compile 'io.grpc:grpc-auth:1.12.0'
    compile 'com.google.api.grpc:grpc-google-cloud-pubsub-v1:0.1.22'
    compile 'javax.annotation:javax.annotation-api:1.2'
    compile 'junit:junit:4.12'
    compile 'com.google.auth:google-auth-library-oauth2-http:0.9.1'
    androidTestCompile 'com.android.support.test:rules:1.0.1'
    androidTestCompile 'com.android.support.test:runner:1.0.1'
}

protobuf {
    protoc {
        artifact = 'com.google.protobuf:protoc:3.0.0'
    }

    plugins {
        javalite {
            artifact = 'com.google.protobuf:protoc-gen-javalite:3.0.0'
        }
        grpc {
            artifact = 'io.grpc:protoc-gen-grpc-java:1.12.0'
        }
    }

    generateProtoTasks {
        all().each { task ->
            task.builtins {
                remove java
            }
            task.plugins {
                javalite {}
                grpc {
                    option 'lite'
                }
            }
        }
    }
}

0 个答案:

没有答案