-
-
Save dlew/5db1b780896bbc6f542e7c00a11db6a0 to your computer and use it in GitHub Desktop.
#!/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: https://developer.android.com/topic/libraries/support-library/downloads/androidx-class-mapping.csv | |
# | |
# 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. | |
MAPPING_FILE=path/to/androidx-class-mapping.csv | |
PROJECT_DIR=path/to/android/project | |
replace="" | |
while IFS=, read -r from to | |
do | |
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" |
Awesome this is what we're looking for!!! Thanks for the people here.
how to use this script?
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. https://gist.github.com/draekko/4019f0342553b6c0cbeca1d185245dd1
Hope this helps someone else, thanks for the original, saved me a lot of work.
Thank you, this saved me hours of pain 🙏
after run the script.sh
It seems that there is an error: android.support.v7.widget.GridLayoutManager => androidx.gridlayout.widget.GridLayoutManager
It should be : android.support.v7.widget.GridLayoutManager => androidx.recyclerview.widget.GridLayoutManager
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!
brew install gnu-sed
Thanks.
any idea of migrating away from AndroidX
thank you.