mapbox / mapbox/android-sdk-versions-plugin
Crash in plugin: variant.generateBuildConfigProvider.get() returns null with buildFeatures.buildConfig = false on AGP 8.0+
Nobody has claimed this yet.
- Dominant language
- Groovy
- Stars
- 1
- Forks
- 5
- PR merge metrics
- No merged PRs in 30d
Description
**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:
```kotlin
saveSDKVersionTask.sdkVersionCode = variant.generateBuildConfigProvider.get().versionCode.getOrNull()
```
With a safe fallback:
```kotlin
variant.generateBuildConfigProvider?.get()?.versionCode?.getOrNull()?.let {
saveSDKVersionTask.sdkVersionCode = it
}
```
Or extract the versionCode from `defaultConfig` if possible.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Search the plugin code for the saveSDKVersionTask assignment involving variant.generateBuildConfigProvider and inspect how buildFeatures.buildConfig is handled. Reproduce with buildConfig disabled using the reported AGP and Gradle versions, then verify the build completes without the null crash and SDK version persistence remains correct.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- android, groovy
- Domain
- build-system
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100