-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathandroidx.sh
executable file
·27 lines (23 loc) · 1.09 KB
/
androidx.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#!/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=scripts/androidx-class-mapping.csv
PROJECT_DIR=node_modules/
replace=""
while IFS=, read -r from to
do
replace+="; s/$from/$to/g"
done <<< "$(cat $MAPPING_FILE)"
if [[ "$OSTYPE" == "darwin"* ]]; then
find $PROJECT_DIR \( -name "*.java" -o -name "*.xml" \) -type f -not -path '*/\.git*' -print0 | xargs -0 gsed -i "$replace"
else
find $PROJECT_DIR \( -name "*.java" -o -name "*.xml" \) -type f -not -path '*/\.git*' -print0 | xargs -0 sed -i "$replace"
fi