Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Crash in plugin: variant.generateBuildConfigProvider.get() returns null with buildFeatures.buildConfig = false on AGP 8.0+

未关闭
#49 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
45/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
停滞
技术栈
android, groovy
领域
build-system

调研方向

在插件代码中搜索涉及 variant.generateBuildConfigProvider 的 saveSDKVersionTask 赋值,并检查 buildFeatures.buildConfig 的处理方式。使用报告中的 AGP 和 Gradle 版本,在禁用 buildConfig 的情况下重现该问题,然后验证构建能够在不发生 null 崩溃的情况下完成,并且 SDK 版本的持久化仍然正确。

由索引模型根据 Issue 内容生成。

描述

bug

Describe the bug
The Gradle plugin throws a NullPointerException when trying to access variant.generateBuildConfigProvider.get().versionCode.getOrNull() in modules where buildConfig is disabled.


Stacktrace

Cannot invoke method get() on null object
> saveSDKVersionTask.sdkVersionCode = variant.generateBuildConfigProvider.get().versionCode.getOrNull()

Root cause
Starting with AGP 8.0, variant.generateBuildConfigProvider may be null if buildFeatures.buildConfig = false is explicitly set in the module’s build.gradle. This causes the .get() call to crash.


How to reproduce

  1. Set buildFeatures.buildConfig = false in a module's build.gradle(.kts)
  2. Run the build
  3. Observe the crash when the plugin accesses generateBuildConfigProvider

Expected behavior
The plugin should check whether generateBuildConfigProvider is null before accessing it, or avoid relying on this API if it's deprecated.


Environment

  • AGP version: 8.7.1
  • Gradle: 8.8
  • Android Studio: 2024.2.1 (Ladybug)
  • Plugin version: last

Suggested fix
Replace:

saveSDKVersionTask.sdkVersionCode = variant.generateBuildConfigProvider.get().versionCode.getOrNull()

With a safe fallback:

variant.generateBuildConfigProvider?.get()?.versionCode?.getOrNull()?.let {
    saveSDKVersionTask.sdkVersionCode = it
}

Or extract the versionCode from defaultConfig if possible.

主要语言
Groovy
星标
1
派生
5
PR 合并指标
30 天内没有已合并 PR

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

mapbox/android-sdk-versions-plugin 的其他 Issue

查看 mapbox/android-sdk-versions-plugin 的全部 Issue

相似的 Issue

更多 Build System Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。