Package Exports
- jetifier
- jetifier/bin/jetify
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (jetifier) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
jetifier
The jetifier AdnroidX transition tool in npm format, with a react-native compatible style
Usage for jar/zip/aar files
npm install jetifier
(or maybenpm install -g jetifier
to make it globally available)npx jetifier-standalone <your arguments here>
(usenpx jetifier-standalone -h
for help)
I have not altered the jetifier-standalone distribution in any way.
Other than the npm-specific instructions, consult the official jetifier documentation
Usage for source files
To jetify / convert node_modules dependencies to AndroidX
Imagine you are a react-native project and one of your library dependencies converts to AndroidX. Now you need to convert your app, but react-native links source code directly and jetifier doesn't handle that.
If there was a way to take your react-native dependencies and convert them, then you could convert your app and use AndroidX dependencies.
There is a way.
- Make sure your app is AndroidX (this is documented elsewhere but is just a refactor in Android Studio)
npm install --save-dev jetifier
(or use yarn, but install it locally in your project, not globally)npx jetify
- Get a cup of coffee, it takes a while. Performance improvements can come later.
npx react-native run-android
(this should compile and work)- If it works, you should hook an
npx jetify
run in the postinstall target of your package.json so you don't forget to run it after installing or updating packages. There will be performance improvements soon (I think) which will make this less painful
Please note that any time you install a new dependency, or reinstall node modules, you will need to run npx jetify
again.
I demonstrate exactly this with a huge pile of native modules here: https://github.com/mikehardy/rn-androidx-demo. You can clone that repo, run the script, and see it works. Please feel to make PRs to that repo, especially in App.js or in the dependencies included, if you would like to demonstrate success or failure for a specific module.
Inspiration: this jetify command was based on an idea from @janicduplessis - thank you Janic!
Troubleshooting
Unfortunately jetifier can't solve all your problems. Here are some reasons it could fail:
- You have a dependency that packages things in violation of Android packaging rules, like including an extra AndroidManifest.xml or similar: https://github.com/acaziasoftcom/react-native-bottomsheet/pull/23 - this will lead to dex merger issues about duplicate entries. Open pull requests with the libraries that do this.
- You have a dependency that does not allow overrides of compileSdk, so you can't set the compileSdk to 28 as AndroidX requires: https://github.com/razorpay/react-native-razorpay/pull/201. This can lead to errors in resource merger where styles reference unknown attributes. Open pull requests with the libraries that do this
- For windows you must use WSL - we have reports it works, but also reports you may need to update WSL and install jetifier locally vs globally. It should work for you, but if you have updates to exactly how to make it work please propose a PR to this readme ♥️
- from one of the success reports "installed jetifier from the Windows console, then I ran the the jetify command from WSL"
So far there has not been a case of npx jetify
failing that wasn't based in an error in a library, so if you have a problem please examine the error and the dependency very closely and help the libraries with fixes.
Contributing
Please feel free to pull requests or log issues, especially to update versions if I somehow fail to notice an update. Thanks!