Skip to content

feat(android)!: compile against @nativescript/core through org.nativescript:gradle-api (needs CLI 9.2) - #22

Draft
edusperoni wants to merge 2 commits into
masterfrom
feat/nativescript-gradle-api
Draft

edusperoni wants to merge 2 commits into
masterfrom
feat/nativescript-gradle-api

Conversation

@edusperoni

@edusperoni edusperoni commented Nov 23, 2026 •

Copy link
Copy Markdown

Draft, don't merge yet. It depends on org.nativescript:gradle-api:0.1.0-alpha.2, which isn't released on Maven Central yet, and on NativeScript CLI 9.2 (NativeScript/nativescript-cli#6175). Until both are out, building this plugin fails.

Example of a plugin adopting org.nativescript:gradle-api, the Gradle library proposed in NativeScript/nativescript-cli#6175, following the discussion in NativeScript/nativescript-cli#6175 (comment).

What changes

The whole include.gradle becomes:

dependencies {
    implementation "androidx.annotation:annotation:1.1.0"

    if (project.hasProperty("tempBuild")) {
        // NativeScript CLIs before 9.2 don't load org.nativescript:gradle-api in this plugin's own aar build.
        if (project.extensions.findByName("nativescript") == null) {
            throw new GradleException("@nativescript-community/gesturehandler needs NativeScript CLI 9.2 or newer: npm i -D nativescript@latest")
        }
        def core = nativescript.findPlugin("@nativescript/core") ?: nativescript.findPlugin("@akylas/nativescript")
        if (core == null) {
            throw new GradleException("@nativescript-community/gesturehandler needs @nativescript/core or @akylas/nativescript")
        }
        compileOnly core.artifacts
    }
}

plus a new platforms/android/buildscript.gradle that puts the library on the build classpath from Maven Central.

  • What goes away: the node_modules paths, the package.json parsing, the widgets-release.aar / nativescript.aar name check, the flatDir repository and the JsonSlurper import. The library knows where core is, including when the CLI keeps node_modules untouched (pluginBuildLocation: "platforms").
  • compileOnly instead of implementation: the app already links core, and this plugin's .aar shouldn't carry core's classes. core.artifacts is every .aar/.jar core ships.
  • Why tempBuild: that's the CLI's build of this plugin's own .aar, the only place this plugin needs core's classes. In that build the CLI only runs the dependencies {} block of include.gradle, and from 9.2 it loads the library there.
  • The first check turns an older CLI's unhelpful "unknown property 'nativescript'" into a message that says what to do.
  • @akylas/nativescript is still found, through the library instead of package.json parsing.

Requirements

  • NativeScript CLI 9.2 or newer. The 9.2 CLI builds projects made with older CLIs and is installed per project, so apps only update a dev dependency. This should go out as a major version.
  • Android runtime 8.4 or newer, because the library is built for Java 11 / Gradle 7.5.

Testing

  • The CLI's own include.gradle extraction keeps the whole block.
  • The same pattern (with plugin("@nativescript/core")) is covered by the library's tests: the CLI's real plugin-build template (AGP 8.12.1) compiles a Java class against a class from a fixture core .aar, through the facts file, with plugins built in node_modules and in platforms. The 9.1 template gives the "needs CLI 9.2" message.
  • Not yet done: compiling this exact file, and a real app build. Both need alpha.2 released.

…cript:gradle-api

The plugin's own aar build finds core's Android libraries with the
nativescript extension when the CLI provides it, instead of building a path
into node_modules. On CLIs that don't load the library in that build, the
existing tempBuild code runs unchanged.
…es lookup

The plugin's own aar build gets core's Android libraries from
org.nativescript:gradle-api 0.1.0-alpha.2, which NativeScript CLI 9.2+ loads
in that build. Older CLIs get a clear error instead of a path into
node_modules.
@edusperoni edusperoni changed the title feat(android): compile against @nativescript/core through org.nativescript:gradle-api feat(android)!: compile against @nativescript/core through org.nativescript:gradle-api (needs CLI 9.2) Nov 27, 2026

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