Skip to content

Instantly share code, notes, and snippets.

Created November 9, 2018 16:36
Star You must be signed in to star a gist
Save dlew/5db1b780896bbc6f542e7c00a11db6a0 to your computer and use it in GitHub Desktop.
Simple AndroidX Migration Script
#!/usr/bin/env bash
# I've found that the "Migrate to AndroidX" converter in Android Studio doesn't work very
# well, so I wrote my own script to do the simple job of converting package names.
# You can download a CSV of package names here:
# It'll run faster on a clean build because then there are fewer files to scan over.
# Uses `gsed` because I'm on a Mac. Can easily replace with `sed` if you don't have `gsed`.
# This isn't perfect; it won't find every conversion issue. You break it you buy it. Viewer discretion is advised.
while IFS=, read -r from to
replace+="; s/$from/$to/g"
done <<< "$(cat $MAPPING_FILE)"
find $PROJECT_DIR \( -name "*.kt" -o -name "*.java" -o -name "*.xml" \) -type f -not -path '*/\.git*' -print0 | xargs -0 gsed -i "$replace"
Copy link

himattm commented Nov 14, 2018

Thanks for this!

Copy link

Thank you!

Copy link

ondrj commented Nov 20, 2018

Great job, thanks a lot!

Copy link

Thanks Dan Leu
We can add,,

to the csv if using AppBarLayout and FloatingActionButton

Copy link

Some more missing classes:,,,,

Copy link

Kisty commented Nov 28, 2018

Thanks for this, Dan!

Android relevant issue for missing mappings:

Copy link

AndiMiko commented Feb 8, 2019

This string doesn't work on windows 10 or Linux. "xargs: Argument list too long" even with just few files

Copy link

AndiMiko commented Feb 9, 2019

I wrote a python script which can be used cross-platform in case you have the same issue:

Copy link

On Mac run: brew install gnu-sed to get gsed.

Copy link

Thanks a Ton Dan!

Copy link

Oh my goodness, thank you!!

Copy link

loganj commented Jun 19, 2019

Here is a much faster version – replaces find with rg and sed with perl, and I think it works just as well. I terminated the original script after 28 minutes. This rg/perl version completed after about 1 minute.

Copy link

Thanks Dan. I wrote a script based on your idea with some added enhancements:

Copy link

maxpinto commented Jul 5, 2019

thank you.

Copy link

mochadwi commented Nov 8, 2019

Awesome this is what we're looking for!!! Thanks for the people here.

Copy link

how to use this script?

Copy link

draekko commented Dec 28, 2019

Did a fork for Linux (i'm on Ubuntu) to work around the xarg too long argument list error, and assumes the csv file is in the same directory as the script.

Hope this helps someone else, thanks for the original, saved me a lot of work.

Copy link

Thank you, this saved me hours of pain 🙏

Copy link

after run the
It seems that there is an error: => androidx.gridlayout.widget.GridLayoutManager
It should be : => androidx.recyclerview.widget.GridLayoutManager

Copy link

I've noticed a substantial performance improvement by running gradle clean before running this script.
The comment on line 8 suggests this but it is easy to overlook.

It'll run faster on a clean build because then there are fewer files to scan over.

The script now runs in 18s instead of 2m43s!

Copy link

bikcrum commented Jun 24, 2021

brew install gnu-sed


Copy link

any idea of migrating away from AndroidX

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