Skip to content
Python Script to automatically migrate imports to AndroidX
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.gitignore
LICENSE
README.md
androidx-class-mapping.csv
migrateToAndroidX.py

README.md

MigrateToAndroidX

Python Script to automatically migrate old imports in a React-Native project to AndroidX imports

What does it do?

  • Uses the bindings file provided by Android
  • Looks at all the node_modules java files and searches for the old bindings (Usually of the form android.support.*) and replaces with the new AndroidX imports(Of the form androidx.*)
  • 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:-
  1. android.support.annotation.**
  2. android.support.annotation.RequiresPermission.**
  3. android.support.design.**
  4. android.support.v4.**

Usage

python3 migrateToAndroidX.py --node_modules <path>

Example

If your path is ~/projects/rnProject/node_modules/ python3 migrateToAndroidX.py --node_modules ~/projects/rnProject/node_modules/

How to make this script run automatically after npm install

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>"
}
You can’t perform that action at this time.