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

Android Apollo3 本地Schema未找到问题求助

排查Apollo Schema文件未找到问题

问题背景

尝试使用本地Schema(源取自https://spacex-production.up.railway.app/),在data模块配置Apollo后运行触发Schema文件未找到错误。

配置代码

apollo {
    service("RocketsGraphQL") {
        packageName.set("com.example.data")
        schemaFiles.from("src/main/graphql/schema.graphqls")
    }
}

错误信息

Caused by: java.lang.IllegalStateException: No schema file found in:

Schema文件内容

"""
type Address {
    """
    address: String

    """
    city: String

    """
    state: String
}

排查步骤

  • 校验文件路径准确性
    确认src/main/graphql/schema.graphqls是相对于data模块根目录的路径。多模块项目中,需确保文件位于data模块的对应目录下(比如完整路径为./data/src/main/graphql/schema.graphqls),而非根项目或其他模块。

  • 核对文件名与扩展名
    确认文件名拼写为schema.graphqls(注意不要写成schema.graphql或其他变体),扩展名与配置中指定的一致。Apollo插件默认支持.graphqls和.graphql后缀,但需保证配置与实际文件匹配。

  • 检查文件所在目录
    确保graphql目录在src/main/下,而非src/test/或其他目录。若插件扫描存在异常,可尝试将Schema文件移至src/main/resources/graphql/schema.graphqls,并修改配置路径为src/main/resources/graphql/schema.graphqls。

  • 验证Gradle模块配置
    确认data模块的build.gradle已正确应用Apollo插件,示例配置如下:

    plugins {
        id("com.apollographql.apollo3") version "指定对应版本号"
    }
    

    确保插件版本有效,且无其他配置覆盖schemaFiles设置。

  • 清理缓存后重新构建
    执行./gradlew clean build(Windows系统使用gradlew clean build)清理项目缓存,再重新构建,排除缓存导致的文件识别异常。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.18 16:02:41