-
-
Save dudeinthemirror/cb4942e0ee5c3df0fcb678d1798e1d4d to your computer and use it in GitHub Desktop.
#! /bin/bash | |
# shellcheck disable=SC2086 | |
# shellcheck disable=SC2162 | |
# This script provides a workaround for having dependent modules which | |
# have not been migrated to AndroidX | |
# see: https://developer.android.com/jetpack/androidx/migrate | |
# inspired from https://gist.github.com/dlew/5db1b780896bbc6f542e7c00a11db6a0 | |
SCRIPTS_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" | |
PROJECT_DIR="$(cd "${SCRIPTS_DIR}"/.. && pwd)" | |
MAPPING_FILE="$SCRIPTS_DIR/androidx_class_map.csv" | |
GSED=$(command -v gsed) | |
if [[ -z "$GSED" ]]; then | |
echo "ERROR: you need to install gnu-sed first." | |
echo "run: 'brew install gnu-sed'" | |
exit 101 | |
fi | |
replace="" | |
while IFS=, read -r from to | |
do | |
replace+="s/\<$from\>/$to/g;" | |
done <<< "$(cat $MAPPING_FILE)" | |
i=0 | |
(find $PROJECT_DIR \( -name "*.kt" -o -name "*.java" -o -name "*.xml" \) -type f ! -path '*/\.git*' ! -path '**/android/app/build/*' ! -path '**/\.idea/*' 2>/dev/null | | |
while read file | |
do | |
grep -E "android.arch|android.databinding|android.support" $file > /dev/null 2>/dev/null | |
ret=$? | |
if (( ! ret )); then | |
$GSED -i.bak "$replace" $file | |
cmp --silent $file $file.bak | |
ret=$? | |
if (( ret ));then | |
printf "\nDoing file %s\n" $file | |
else | |
i=$((i+1)) | |
printf '\r%2d skipped' $i | |
rm -f $file.bak | |
fi | |
fi | |
done | |
echo | |
) |
Hi, @dudeinthemirror !
My AS is highlighting me androidx.test.InstrumentationRegistry
is deprecated.
So, I would recommend to update this line:
android.support.test.InstrumentationRegistry,androidx.test.platform.app.InstrumentationRegistry
hey @atetc, thanks for the heads up! I updated the .csv file.
good job,thanks man.
For ubuntu 18.04
https://gist.github.com/AbdElraoufSabri/907163eecbb87e7ca033d01004623c05
Features
- one command download and execute
- using sed
- linux compatible
Seems to work great in a multi-project build! Thanks for this!
@dudeinthemirror
In general, substrings should come first in the mapping file. For example, the following two should be reversed to prevent GridLayoutManager
from being changed to an incorrect import.
@kedarmp, very good catch, thanks. I updated the sed predicate to look for the exact word boundary \< \>
This was inspired by the original script published by Dan Lew here: https://gist.github.com/dlew/5db1b780896bbc6f542e7c00a11db6a0
It has a few enhancements:
android/app/build
and.idea
directories when searching for filesandroid.arch
,android.databinding
andandroid.support
gsed
if it is not foundscripts
dir under the root of the project and both this script and the .csv file (androix_class_map.csv
) reside in this dir