Repository navigation
feat(android)!: compile against @nativescript/core through org.nativescript:gradle-api (needs CLI 9.2) - #22
Draft
edusperoni wants to merge 2 commits into
Draft
edusperoni wants to merge 2 commits into
edusperoni wants to merge 2 commits into
Conversation
…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.
4 of 5 tasks
…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.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.gradlebecomes: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.gradlethat puts the library on the build classpath from Maven Central.node_modulespaths, thepackage.jsonparsing, thewidgets-release.aar/nativescript.aarname check, theflatDirrepository and theJsonSlurperimport. The library knows where core is, including when the CLI keepsnode_modulesuntouched (pluginBuildLocation: "platforms").compileOnlyinstead ofimplementation: the app already links core, and this plugin's.aarshouldn't carry core's classes.core.artifactsis every.aar/.jarcore ships.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 thedependencies {}block ofinclude.gradle, and from 9.2 it loads the library there.@akylas/nativescriptis still found, through the library instead ofpackage.jsonparsing.Requirements
Testing
include.gradleextraction keeps the whole block.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 innode_modulesand inplatforms. The 9.1 template gives the "needs CLI 9.2" message.