Python Script to automatically migrate old imports in a React-Native project to AndroidX imports
- Uses the bindings file provided by Android
- Looks at all the
node_modulesjava files and searches for the old bindings (Usually of the formandroid.support.*) and replaces with the new AndroidX imports(Of the formandroidx.*) - Currently, I'm only looking for a sublist of imports (that is used by most react-native libraries) and replacing them. The sublist of imports are below:-
android.support.annotation.**android.support.annotation.RequiresPermission.**android.support.design.**android.support.v4.**
python3 migrateToAndroidX.py --node_modules <path>
If your path is ~/projects/rnProject/node_modules/
python3 migrateToAndroidX.py --node_modules ~/projects/rnProject/node_modules/
It might be beneficial to run the script after all node_modules are installed.
For this, we can use postinstall hook of npm
In your package.json, you can add a new script,
"scripts":{
...
"postinstall":"python3 migrateToAndroidX.py --node_modules <path>"
}