NativeScript 6.0 release is planned for this July and with it comes support for AndroidX. We are also dropping support for Android Support Library which is a breaking change and means code depending on it should be migrated.
This blog will guide you, as a plugin developer, can do to prepare for the release.
Each nativescript plugin falls in one of following categories:
- There is no need to migrate the plugin. YEY!
- Plugin can be made compatible with both support-lib and AndroidX.
- There is no compatibility path. You should publish an AndroidX-only version of the plugin to make it usable with NativeScript 6.0.
Here is a flowchart that will help you determine which category does your plugin fall into:
Let's see what is the recommended way to go froward in each case.
example: nativescript-localstorage
If your plugin (and its dependencies) does not depend on android support lib in any way - you are off the hook. You can stop reading now.
example: nativescript-permissions
In some cases it is possible to make your plugin compatible with both support-lib and androidX by performing a runtime check to know which one is available. You can check this awesome blog by Nathanael Anderson on how to do that.
Note: If you are extending support-lib classes or have native dependency that uses support-lib you won't fall in this category.
The good part is that you can do this now and your plugin will be useable with NS 6 when it comes out.
example: nativescript-facebook
It might is just not possible for your plugin to be compatible with both support-lib and AndroidX. This can be due to multiple reasons: Java code or third party lib depends on support-lib, you are extending support-lib classes in your JS code, you have support lib configuration in android-manifest.xml
, etc.
In all cases you should be able to migrate your plugin to AndoridX. You can use jetifier for the native dependencies and/or androidx-migration-tool for your JS/TS/JAVA code. You can also check support for AndroidX in NativeScript for tips on migration. The important thing is that you can start now using the anfroidx
builds of the android-runtime and tns-core-modules:
npm install tns-core-modules@androidx --save-exact
tns platform add android@androidx
npm install tns-platform-declarations@androidx --save-exact (if you need typings)
Here is the recommended action plan:
- Migrate the plugin.
- Bump a major version and publish it behind
androidx
tag in npm:$npm publish --tag androidx
- [When NativeScript 6.0 is out] Publish the AndroidX version. It's a good idea to add a peerDependency to
"tns-core-modules": ">6.0.0"
.
Note: Publishing behind
androidx
tag before the official NativeScript 6 release will give a chance to other plugins and applications that depend on it to be tested.
Handling breaking changes can be tedious, but we are here to help. Reach out to us in nativescript slack - #androidx-migration channel if you get stuck.
You can use jetifier for the native parts and/or androidx-migration-tool for your JS/TS code.
It sounds like jetifier will migrate your .java files too, which is something that the androidx-migration-tool will actually do. Just a suggestion:
You can use jetifier for the native dependencies and/or androidx-migration-tool for your JS/TS/JAVA code.