Skip to content

fix(android): give plugins with clashing short names unique aar names - #6217

Open
edusperoni wants to merge 1 commit into
mainfrom
fix/unique-plugin-aar-names
Open

edusperoni wants to merge 1 commit into
mainfrom
fix/unique-plugin-aar-names

Conversation

@edusperoni

@edusperoni edusperoni commented Nov 27, 2026 •

Copy link
Copy Markdown
Collaborator

PR Checklist

What is the current behavior?

The CLI names a plugin's built .aar, its temporary build project (platforms/tempPlugin/<name>) and the org.nativescript.<name> namespace fallback after the plugin's short name, which drops the npm scope. Two plugins such as @foo/plugin-x and @bar/plugin-x therefore both build plugin_x.aar, share one temp build folder and get the same fallback namespace. Which plugin's code ends up in the app depends on build order. (#6132 proposed an aarSuffix option to work around it.)

What is the new behavior?

Each native Android plugin gets an .aar name that is unique in the project, with no option needed.

  • No clash, no change. A plugin whose short name no other native plugin shares keeps it, so those projects build exactly as before: same dependencies.json, same .aar names and paths (asserted in tests).
  • On a clash, scoped plugins get <scope>_<short> (e.g. foo_plugin_x); an unscoped plugin keeps the short name; a name starting with a digit gets a leading _. The result doesn't depend on dependency order. If two plugins still end up with the same name (e.g. @foo/plugin-x and @foo/plugin_x), prepare fails and names both packages.
  • Leftovers from the old name. Old Gradle templates add every *.aar in a plugin's platforms/android to the app, so a file built under the previous name would add duplicate classes. Only for plugins the CLI builds (they have a manifest or Android sources):
    • <short>.aar is always a leftover: earlier CLIs copied every build there, overwriting anything the package shipped under that name. It's deleted.
    • <scope>_<short>.aar is a leftover only if its temp build project was built for this plugin (its build.gradle names it) and has that output: identical → deleted; different → prepare stops with both paths and "delete it or run ns clean". Otherwise the package ships it and it's kept.
    • Plugins the CLI doesn't build (prebuilt only) never have anything deleted.
  • Upgrading a project that already has a clash rebuilds the renamed .aars once and removes the old <short>.aar from each clashing plugin, with no manual step.

ns plugin build is unchanged. Split out of #6175, which builds on it (the facts file there records each plugin's .aar name).

Summary by CodeRabbit

  • New Features

    • Android plugin builds now use distinct AAR names when plugins share the same short name, while retaining familiar names when there’s no conflict.
    • Plugin builds can be checked for missing or outdated AAR outputs.
  • Bug Fixes

    • Conflicting plugin names that would produce the same AAR name are reported as an error instead of silently colliding.
    • Outdated generated AARs are cleaned up before rebuilding, while shipped AARs are preserved.

The CLI names a plugin's aar, its temp build project and the
`org.nativescript.<name>` namespace fallback after the plugin's short
name, which drops the npm scope. Two scoped plugins with the same name,
such as `@foo/plugin-x` and `@bar/plugin-x`, therefore both build
`plugin_x.aar`, share `platforms/tempPlugin/plugin_x` and get the same
fallback namespace. Which plugin's code ends up linked depends on the
order they are built in.

Each native Android plugin now gets an aar name that is unique in the
project. A plugin whose short name no other native plugin shares keeps
it, so projects without a clash build exactly as before: same
dependencies.json, same aar names and paths. Within a group of plugins
that share a short name, scoped plugins get `<scope>_<short>` (the scope
without `@`, with characters other than [A-Za-z0-9_] replaced by `_`),
an unscoped plugin keeps its short name, and a name that would start
with a digit gets a leading `_`. The result does not depend on the
order of the dependencies. If two plugins still end up with the same
name, prepare fails and names both packages. `ns plugin build` is
unchanged.

Old Gradle templates add every *.aar in a plugin's platforms/android to
the app, so an aar the CLI built under the plugin's previous name would
add duplicate classes. When the CLI builds a plugin (it has a manifest
or Android sources), each aar in its platforms/android named after
another of its candidate names is handled as follows:
- the plain short name: earlier CLIs always copied the built aar to
  `<short>.aar`, overwriting anything the package shipped under that
  name, so the file is a leftover and is deleted;
- the scope-qualified name: only this CLI builds it, so the file is a
  leftover only when `<tempPlugin>/<name>/build.gradle` sets
  `project.ext.PLUGIN_NAME` to this plugin's npm name and the temp
  project has a build output at
  `<tempPlugin>/<name>/build/outputs/aar/<name>-release.aar`. If the
  file is byte-identical to that output it is deleted; if it differs,
  prepare fails with both paths and asks to delete it or run
  `ns clean`. Otherwise the package ships it and it is left alone.
Aars of plugins the CLI does not build are never deleted or flagged.

The Android project service reports a plugin for reprepare while its
aar is missing under the new name or a leftover is still there, so
upgrading the CLI on a project with a clash rebuilds the renamed aars
and deletes the old `<short>.aar` in each clashing plugin.
@coderabbitai

coderabbitai Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Android plugin preparation now assigns unique AAR names to native dependencies and passes those names to the build service. The service uses them for build outputs and checks, and identifies and removes certain stale candidate AARs.

Changes: Android plugin AAR naming and builds

Layer / File(s) Summary
Plugin AAR name mapping
lib/common/helpers.ts, lib/common/test/unit-tests/helpers.ts, lib/definitions/android-plugin-migrator.d.ts, lib/services/android-project-service.ts, test/services/android-project-service.ts, test/stubs.ts
New helpers generate unique short AAR names and candidate names. AndroidProjectService caches names for native Android dependencies, uses them in plugin build options, and reports naming collisions. Tests cover name resolution, project preparation, and reprepare checks.
Named AAR builds and stale output handling
lib/services/android-plugin-build-service.ts, test/services/android-plugin-build-service.ts
The build service uses the selected AAR name for temporary project paths, output paths, and Gradle setup. It checks for outdated AARs and removes identified stale candidates, failing when prior build output differs. Tests cover naming, stale-file handling, and outdated checks.

Estimated code review effort: 4 (Complex) | ~45 minutes

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant AndroidProjectService
  participant AndroidPluginBuildService
  participant FileSystem
  participant Gradle
  AndroidProjectService->>AndroidPluginBuildService: prepare plugin with mapped aarName
  AndroidPluginBuildService->>FileSystem: inspect candidate AARs and prior build metadata
  AndroidPluginBuildService->>FileSystem: remove identified stale AARs
  AndroidPluginBuildService->>Gradle: build using selected aarName
  Gradle->>AndroidPluginBuildService: return built AAR
  AndroidPluginBuildService->>FileSystem: copy AAR to configured output directory
Loading

Possibly related PRs

Suggested reviewers: rigor789, nathanwalker

Merge Risk: Minimal · up to 389aa

The change gives Android plugins with clashing short names unique AAR names, temporary build folders and fallback namespaces, and leaves non-clashing plugins unchanged. No concrete merge-blocking risk was found in the reviewed changes, and the tests cover the new naming and stale-AAR handling.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title "fix(android): give plugins with clashing short names unique aar names" matches the main change. The PR makes Android plugins whose short names clash receive unique AAR names. It uses scope-…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "fix(android): give plugins with clashing short names unique aar names" matches the main change. The PR makes Android plugins whose short names clash receive unique AAR names. It uses scope-qualified names on a clash, prefixes leading digits, and fails with an error when names still collide. The changed files (android-plugin-build-service, android-project-service, helpers, and related tests and definitions) all support this change. The title is short, specific, and follows a conventional commit format.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

A rabbit named plugins hopped out of the den,
With scoped AAR names, they lined up again.
The old stray files took a neat little flight,
Gradle built new ones by moonbeam and night.
“Unique names for all!” cheered the rabbit, quite right.

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: d22da51b-3198-479f-9805-1d41352a065c
Commits

Reviewing files that changed from the base of the PR and between c7e0c5b and 389aa01.

Files selected for processing: 8

  • lib/common/helpers.ts
  • lib/common/test/unit-tests/helpers.ts
  • lib/definitions/android-plugin-migrator.d.ts
  • lib/services/android-plugin-build-service.ts
  • lib/services/android-project-service.ts
  • test/services/android-plugin-build-service.ts
  • test/services/android-project-service.ts
  • test/stubs.ts

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 2 remain after this review.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant