Fix same-config change advice crash in KMP projects#1650
Fix same-config change advice crash in KMP projects#1650NikolayMetchev wants to merge 2 commits intoautonomousapps:mainfrom
Conversation
…ousapps#1649) In KMP projects with both Android and JVM targets, a dependency declared on androidMainImplementation that is used in androidMain would crash buildHealth with "Change advice cannot be from and to the same configuration". This happened because simplify() paired an add and remove for the same configuration and tried to create an invalid change advice. Now, when from == to, the add and remove cancel out silently. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
autonomousapps
left a comment
There was a problem hiding this comment.
I am not certain this is the correct solution. If we get to this point with from and to being the same configuration, that implies something flawed in the analysis. Simply not crashing here might hide a deeper flaw.
KmpSourceKind was a data class whose equality included compileClasspathName
and runtimeClasspathName. When KmpSourceKind.of(compilation) constructed a
sourceKind from real Android compilations (e.g. debugCompileClasspath), it
differed from what ConfigurationNames.sourceKindFrom("androidMainImplementation")
produced (androidMainCompileClasspath). This mismatch caused usages and
declarations to never match in computeAdvice(), generating both ofAdd and
ofRemove for the same configuration, which then crashed in simplify() with
IllegalArgumentException (from == to).
Fix: override equals/hashCode/compareTo in KmpSourceKind to compare by name
only. KMP source set names are unique identifiers; classpath names are derived
values that don't provide additional discriminating power.
Also reverts the prior symptomatic fix (skipping from==to in simplify()) in
favour of this proper root cause fix, and adds a unit test that directly
reproduces the crash (IllegalArgumentException) without requiring Android SDK.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
You're right — the original fix was masking a deeper flaw. I've pushed a new commit that addresses the root cause. Root cause:
Because these differ, usage and declaration Fix: Override The prior symptomatic guard in |
|
See #1673 Also, please note that I have recently added a code of conduct, and now LLM-generated content is strictly forbidden for both issues and PRs. |
Summary
buildHealthcrashes with"Change advice cannot be from and to the same configuration (androidMainImplementation)"in KMP projects with both Android and JVM targetsStandardTransform.simplify(), when a matching add+remove pair has the same configuration (from == to), they now cancel each other out instead of crashingTest plan
SameConfigKmpProjectreproduces the crash (verified it fails without the fix)🤖 Generated with Claude Code