Repository navigation
fix: resolve Android dependencies on AGP 9 - #1087
Conversation
This avoids a ConcurrentModificationException, when resolving a configuration adds a new one to the project configuration list.
AGP's variant configurations, such as debugCompileClasspath, don't request an artifact type. Resolving them directly fails as soon as they include another Android module, and otherwise yields .aar files, which the aggregator ignores. Request the android-classes-jar artifacts AGP compiles against instead, so Android dependencies get Maven coordinates. Amp-Thread-ID: https://ampcode.com/threads/T-01a1e90a-ee48-77ee-acba-7dd64721effc Co-authored-by: Amp <amp@ampcode.com>
chrapkowski-sg
left a comment
There was a problem hiding this comment.
Nice fix. Matching on the BuildTypeAttr attribute and requesting android-classes-jar to mirror AGP's own compile path makes sense to me. Two small suggestions:
1. Make the artifact view lenient. The old branch never transformed anything, but this view is strict, so a single artifact that has no transform chain to android-classes-jar (or a transform that fails) now makes us skip every dependency in that configuration. I haven't reproduced this; candidates would be a klib/zip artifact, a malformed AAR, or AARs on the annotation-processor classpath, which AGP itself never resolves this way. Something like this would keep the rest of the jars:
view.lenient(true);
...
ArtifactCollection artifacts = conf.getIncoming().artifactView(...).getArtifacts();
artifacts.getFailures().forEach(failure ->
getLogger().warn("Skipping artifact in '" + conf.getName() + "': " + failure.getMessage()));
artifacts.forEach(artifact -> { ... });2. Project dependencies are now dropped, but only on Android configurations. Before this change, an Android variant whose project dependencies were all Java modules resolved fine and wrote a line like group core unspecified <classes dir>. The ModuleComponentIdentifier filter now drops those, while the non-Android branch still writes them. The impact is probably small, since a published sibling writes its own line from its own task. Still, could you add a short comment on the filter (or a sentence in the description) so it's clear this asymmetry is intended?
A single artifact that can't be transformed to android-classes-jar now only skips itself, with a warning, instead of the whole configuration. Also note why the view leaves out project dependencies. Amp-Thread-ID: https://ampcode.com/threads/T-01a1e90a-ee48-77ee-acba-7dd64721effc Co-authored-by: Amp <amp@ampcode.com>
On AGP 9,
scipPrintDependenciescrashed with aConcurrentModificationException, because resolving a configuration adds a new one to the project's configuration list. Iterating over a copy fixes that. The configuration AGP adds there (androidApis, holdingandroid.jar) has no Maven coordinates, so skipping it loses nothing.Once the task ran, every Android variant classpath that includes another Android module still failed to resolve, and the ones that did resolve listed
.aarfiles, which the aggregator ignores. AGP's variant configurations don't request an artifact type, AGP always resolves them through an artifact view. We now do the same for configurations carrying AGP's build type attribute, asking forandroid-classes-jar, which gives the same transformed jars the Kotlin compile uses. On the AGP 9.1 / Kotlin 2.3 repro fixture from #864 this goes from 29 skipped configurations to none, and AndroidX symbols now get Maven coordinates.Partially fixes #864: auto-mode still doesn't trigger Android compile tasks, so Android projects need an explicit build command like
scip-java index -- clean scipPrintDependencies compileDebugKotlin.