You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Android项目升级protoc到4.28.0后出现IntListAdapter找不到符号错误

Protobuf 4.28.0升级后IntListAdapter找不到的解决办法

问题背景

在Android项目中将com.google.protobuf:protoc版本从4.27.5升级至4.28.0后,项目构建出现以下错误:

error: cannot find symbol private static final com.google.protobuf.Internal.IntListAdapter.IntConverter< ^ symbol:   class IntListAdapter location: class Internal

项目中的protobuf Gradle配置如下:

protobuf {
    //dependency versions are defined under runtime-android/gradle/libs.versions.toml file
    protoc { artifact = "com.google.protobuf:protoc:${libs.versions.protobuf.protoc.get().toString()}" }
    plugins {
        grpc { artifact = "io.grpc:protoc-gen-grpc-java:${libs.versions.grpc.java.get().toString()}" }
        grpckt { artifact = "io.grpc:protoc-gen-grpc-kotlin:${libs.versions.grpc.kt.get().toString()}" }
    }
    generateProtoTasks {
        all().each { task ->
            task.dependsOn syncProtos

            task.builtins {
                java {
                    option("lite")
                }
            }
            task.plugins {
                grpc {
                    option("lite")
                }
                grpckt {
                    option("lite")
                }
            }
        }
    }
}

尝试修改protobufKotlin和protobufJava版本后问题未解决。

解决步骤

1. 移除对内部API的直接引用

IntListAdapter是Protobuf Lite的内部API,4.28.0版本中它从com.google.protobuf.Internal包迁移到了com.google.protobuf.Internal.lite包,且这类内部API不保证兼容性。检查项目中自定义代码或生成的Proto代码,如果存在直接引用com.google.protobuf.Internal.IntListAdapter的逻辑,替换为官方公开API:

  • 使用com.google.protobuf.LazyStringArrayList替代自定义列表实现
  • 直接使用标准List<Integer>接口,避免依赖内部类

2. 对齐所有Protobuf相关依赖版本

确保项目中所有Protobuf和GRPC相关依赖版本与protoc:4.28.0匹配:

  • 更新libs.versions.toml中的版本:
    • protobuf.protoc = "4.28.0"
    • protobuf.java-lite = "4.28.0"
    • protobuf.kotlin-lite = "4.28.0"
    • GRPC版本需适配Protobuf 4.28.0,例如grpc.java = "1.64.0"、grpc.kt = "1.64.0"(GRPC Java 1.64.0及以上版本支持Protobuf 4.x)
  • 确认模块依赖中使用的是lite版本的库,而非标准版本:
    implementation("com.google.protobuf:protobuf-java-lite:${libs.versions.protobuf.java-lite}")
    implementation("com.google.protobuf:protobuf-kotlin-lite:${libs.versions.protobuf.kotlin-lite}")
    

3. 清理构建缓存并重新生成代码

旧的生成代码可能残留导致冲突,执行以下命令清理后重新构建:

./gradlew clean
./gradlew generateProto
./gradlew assembleDebug

4. 检查Proto文件的Lite配置

确保所有.proto文件顶部声明了Lite运行时选项,避免生成依赖标准运行时的代码:

syntax = "proto3";
option java_package = "your.app.package";
option java_multiple_files = true;
option java_lite_runtime = true; // 必须添加此选项

内容的提问来源于stack exchange,提问作者Satyam Gondhale

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.14 00:17:23