# Android Build: Unresolved reference KSP/Code gen

**URL:** <https://discuss.bitrise.io/t/android-build-unresolved-reference-ksp-code-gen/25725>\
**Category:** Android\
**Tags:** android\
**Created:** [December 16, 2025, 8:25pm UTC](https://discuss.bitrise.io/t/android-build-unresolved-reference-ksp-code-gen/25725 "2025-12-16T20:25:22Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hassan.Badran](https://avatars.discourse-cdn.com/v4/letter/h/b4bc9f/32.png) [@Hassan.Badran](https://discuss.bitrise.io/u/Hassan.Badran)\
**Post date:** [December 16, 2025, 8:25pm UTC](https://discuss.bitrise.io/t/android-build-unresolved-reference-ksp-code-gen/25725/1 "2025-12-16T20:25:22Z")

</div>

We’re experiencing a build failure in Bitrise when running Android test and build steps separately. The issue does not occur locally and appears to be related to how Bitrise caches KSP (Kotlin Symbol Processing) generated code between workflow steps.

We had in the past our own android library that used to generate code of classes annotated with a specific, we migrated the library to be in our main project, eventually the annotation path changed from x.y.z to a.b.c.

The builds will always fail now with **Unresolved reference** error, but with a weird behavior the first step always works the second always fails ( Android Test \<–\> Android Build ), the first one always works the second fails with unresolved reference.

**Reproduction:**

1. **Test step runs first → Build step second** : Test succeeds, but build fails with “Unresolved reference” errors

2. **Build step runs first → Test step second** : Build succeeds, but test fails with “Unresolved reference” errors

We tried another way, we change the annotation path from a.b.c → x.y.z and it doesn’t show **Unresolved reference** error anymore and it is finding the annotations! even though x.y.z never exists in the code base at all anymore, somewhere this is getting cached.

We removed all cache steps, wrote script to remove cache forcefully, nothing works but locally the build works and if we put android build before the test, the build is generated.

---

<div class="post-metadata">

**Author:** ![viktorbenei](https://sea2.discourse-cdn.com/flex016/user_avatar/discuss.bitrise.io/viktorbenei/32/18_2.png) [@viktorbenei](https://discuss.bitrise.io/u/viktorbenei)\
**Post date:** [December 17, 2025, 1:11pm UTC](https://discuss.bitrise.io/t/android-build-unresolved-reference-ksp-code-gen/25725/2 "2025-12-17T13:11:43Z")

</div>

Hi @Hassan.Badran

Can you please contact our support via the support bubble, and send us the URLs of the builds there?

 ![Screenshot 2025-12-17 at 2.04.40 PM](https://us1.discourse-cdn.com/flex016/uploads/bitrise/original/2X/5/5c409e1f261454337f644731bf5abdd3108180e1.png)

* * *

A bit of ideation, but w/o the build URLs it’s really hard to tell:

This really looks like **stale KSP-generated sources / incremental state leaking between the two Bitrise steps**.

What’s happening is: Bitrise runs **two separate Gradle invocations** in the same checkout (`Android Test` then `Android Build`, or the reverse). The first invocation generates (or reuses) KSP outputs for the variants it compiles. The second invocation then compiles a **_different_** set of variants/tasks and ends up seeing a **mismatched mix of generated sources and/or KSP incremental caches** —so it fails with `Unresolved reference`. Flipping the order flips which set of generated outputs is “left behind”, so the failure flips too.

The “we changed annotation path back to x.y.z and it works even though it doesn’t exist anymore” is another strong signal that **old generated code (or cached compilation outputs) referencing the old FQCN is still being picked up** somewhere under `build/` (commonly `build/generated/ksp/...` and `build/kspCaches/...`) or via Gradle build cache/incremental compilation.

### Why this shows up on Bitrise but not locally

Locally you typically run tasks in one session, or you have different cache state. On CI, you get a very reproducible sequence of two clean-ish invocations where the first produces outputs and the second reuses them incorrectly.

### What to do

A few options, in order of practicality:

1. **Run tests + build in a single Gradle invocation** (probably works):

2. **Force cleanup of KSP outputs between steps** (more targeted than `clean`):  
Delete per-module:

3. **As a diagnostic, make the second step run `clean`**  
If adding `./gradlew clean` before the second step makes it go away, it confirms stale build outputs are the root cause. Then you can replace it with the more targeted KSP directory cleanup above.

4. **Temporarily disable incremental/caching on CI to confirm**  
For example on CI only:

5. Run the 2 steps in 2 separate builds, in parallel, e.g. via [Bitrise Pipelines](https://docs.bitrise.io/en/bitrise-ci/workflows-and-pipelines/build-pipelines/about-pipelines.html).  
This way the 2 steps/Gradle commands won’t affect each other.

### Extra thing to check

Make sure your processor is actually applied for all variants you compile (debug vs androidTest vs release). It’s common that `test` triggers `debugAndroidTest` tasks and `build` triggers `release`/`assemble`, and KSP outputs are variant-specific—so one step may not regenerate what the other needs.

If you share the build URLs with our support, we can point to the exact variant mismatch and recommend the cleanest/best solution.
