Skip to content

Instantly share code, notes, and snippets.

@vakrilov
Last active April 24, 2019 11:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vakrilov/f9e4a7478fe651eb6ddb902596d1a964 to your computer and use it in GitHub Desktop.
Save vakrilov/f9e4a7478fe651eb6ddb902596d1a964 to your computer and use it in GitHub Desktop.
AndroidX Plugin Migration Guide

Migrating NativeScript Plugins to AndroidX

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:

  1. There is no need to migrate the plugin. YEY!
  2. Plugin can be made compatible with both support-lib and AndroidX.
  3. 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:

androidx-flowchart

Let's see what is the recommended way to go froward in each case.

No Need To Migrate

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.

Make it Compatible with Both Support-lib and AndroidX

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.

No Compatibility Path

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:

  1. Migrate the plugin.
  2. Bump a major version and publish it behind androidx tag in npm: $npm publish --tag androidx
  3. [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.

Getting Help

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.

@ADjenkov
Copy link

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.

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