-
-
Save vashisthg/79fc02336824a5eaac268d7eae666cca to your computer and use it in GitHub Desktop.
Simple AndroidX Migration Script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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. | |
# Add these bottom lines to the csv if using AppBarLayout and FloatingActionButton | |
# android.support.design.widget.FloatingActionButton,com.google.android.material.floatingactionbutton.FloatingActionButton | |
# android.support.design.widget.AppBarLayout,com.google.android.material.appbar.AppBarLayout | |
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" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment