GRPC从1.25.0更新到1.34.1后找不到simbol错误

Ale*_*nov 1 protocol-buffers proto grpc

如果我使用旧版本,Protobuf 会成功生成我的原型,但是当我将 protobuf 依赖项更新到最新的 1.34.1 时,我总是遇到这个问题。

如果我使用旧版本,Protobuf 会成功生成我的原型,但是当我将 protobuf 依赖项更新到最新的 1.34.1 时,我总是遇到这个问题。

错误

C:\Users\1\AndroidStudioProjects\capella-client-androidd\app\build\generated\source\proto\debug\javalite\api\AbonentOuterClass.java:337: error: an enum switch case label must be the unqualified name of an enumeration constant
        case IS_INITIALIZED: {
             ^
C:\Users\1\AndroidStudioProjects\capella-client-androidd\app\build\generated\source\proto\debug\javalite\api\AbonentOuterClass.java:340: error: an enum switch case label must be the unqualified name of an enumeration constant
        case MAKE_IMMUTABLE: {
             ^
C:\Users\1\AndroidStudioProjects\capella-client-androidd\app\build\generated\source\proto\debug\javalite\api\AbonentOuterClass.java:346: error: an enum switch case label must be the unqualified name of an enumeration constant
        case VISIT: {
             ^
C:\Users\1\AndroidStudioProjects\capella-client-androidd\app\build\generated\source\proto\debug\javalite\api\AbonentOuterClass.java:347: error: cannot find symbol
          Visitor visitor = (Visitor) arg0;
          ^
  symbol:   class Visitor
  location: class LoginRequest
C:\Users\1\AndroidStudioProjects\capella-client-androidd\app\build\generated\source\proto\debug\javalite\api\AbonentOuterClass.java:347: error: cannot find symbol
          Visitor visitor = (Visitor) arg0;
                             ^
  symbol:   class Visitor
  location: class LoginRequest
C:\Users\1\AndroidStudioProjects\capella-client-androidd\app\build\generated\source\proto\debug\javalite\api\AbonentOuterClass.java:353: error: cannot find symbol
          if (visitor == com.google.protobuf.GeneratedMessageLite.MergeFromVisitor
                                                                 ^
  symbol:   variable MergeFromVisitor
  location: class GeneratedMessageLite
Run Code Online (Sandbox Code Playgroud)

我的 gradle 模块

plugins {
    id 'com.android.application'
    id 'kotlin-android'
    id 'com.google.protobuf'
    id 'kotlin-android-extensions'
    id 'kotlin-kapt'
}
 

protobuf {
    protoc { artifact = 'com.google.protobuf:protoc:3.5.1-1' }
    plugins {
        javalite { artifact = "com.google.protobuf:protoc-gen-javalite:3.0.0" }
        grpc { artifact = 'io.grpc:protoc-gen-grpc-java:1.34.1' // CURRENT_GRPC_VERSION
        }
    }

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


android {
    compileSdkVersion 30
    buildToolsVersion "30.0.3"

    defaultConfig {
        applicationId "com.glonass.glonassmobile"
        minSdkVersion 16
        targetSdkVersion 30
        versionCode 1
        versionName "1.0"
        multiDexEnabled true


        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        coreLibraryDesugaringEnabled true
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    kotlinOptions {
        jvmTarget = '1.8'
    }
}

dependencies {

    coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.1'
    def nav_version = "2.3.2"
    def fragment_version = "1.3.0-rc01"
    implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
    implementation 'androidx.core:core-ktx:1.3.2'
    implementation 'androidx.appcompat:appcompat:1.2.0'
    implementation 'com.google.android.material:material:1.2.1'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
    testImplementation 'junit:junit:4.13.1'
    androidTestImplementation 'androidx.test.ext:junit:1.1.2'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'

    //For using fragment result listener
    implementation "androidx.fragment:fragment-ktx:$fragment_version"
    implementation "androidx.fragment:fragment-ktx:$fragment_version"

    implementation "androidx.navigation:navigation-fragment-ktx:$nav_version"
    implementation "androidx.navigation:navigation-fragment-ktx:$nav_version"

    implementation 'io.grpc:grpc-okhttp:1.34.1' // CURRENT_GRPC_VERSION
    implementation 'io.grpc:grpc-protobuf-lite:1.34.1' // CURRENT_GRPC_VERSION
    implementation 'io.grpc:grpc-stub:1.34.1' // CURRENT_GRPC_VERSION
    implementation 'io.grpc:grpc-testing:1.34.1' // CURRENT_GRPC_VERSION
    implementation 'javax.annotation:javax.annotation-api:1.3.2'
    
    implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.1'

}
Run Code Online (Sandbox Code Playgroud)

我的 build gradle 项目

buildscript {
    ext.kotlin_version = "1.3.72"
    repositories {
        google()
        jcenter()
    }

    dependencies {
        classpath "com.android.tools.build:gradle:4.1.1"
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.14'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        maven { url 'https://jitpack.io' }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}
Run Code Online (Sandbox Code Playgroud)

Eri*_*son 5

不保证Java Lite 运行时的API/ABI 稳定。这包括生成的代码和运行时之间的接口。因此,您必须使用与 protobuf-javalite jar 相同版本的 protoc-gen-javalite (在本例中,可能是 3.12.0)。

我看到您正在使用版本 3.0.0 的 protoc-gen-javalite:

    javalite { artifact = "com.google.protobuf:protoc-gen-javalite:3.0.0" }
Run Code Online (Sandbox Code Playgroud)

Java Lite 代码生成已protoc作为内置合并,因此您不再使用插件语法。

protobuf {
    protoc { artifact = 'com.google.protobuf:protoc:3.12.0' }
    plugins {
        grpc { artifact = 'io.grpc:protoc-gen-grpc-java:1.34.1' }
    }

    generateProtoTasks {
        all().each { task ->
            task.builtins{
                java { option 'lite' }
            }
            task.plugins {
                grpc { option 'lite' }
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)