Skip to content

Instantly share code, notes, and snippets.

@dudeinthemirror
Last active July 8, 2021 07:00
Show Gist options
  • Save dudeinthemirror/cb4942e0ee5c3df0fcb678d1798e1d4d to your computer and use it in GitHub Desktop.
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
)
@atetc
Copy link

atetc commented Jul 18, 2019

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

@dudeinthemirror
Copy link
Author

hey @atetc, thanks for the heads up! I updated the .csv file.

@alleniver
Copy link

good job,thanks man.

@abd3lraouf
Copy link

abd3lraouf commented Sep 8, 2019

For ubuntu 18.04

https://gist.github.com/AbdElraoufSabri/907163eecbb87e7ca033d01004623c05

Features

  • one command download and execute
  • using sed
  • linux compatible

@kedarmp
Copy link

kedarmp commented Sep 24, 2019

Seems to work great in a multi-project build! Thanks for this!

@kedarmp
Copy link

kedarmp commented Sep 26, 2019

@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.
image

@dudeinthemirror
Copy link
Author

dudeinthemirror commented Sep 28, 2019

@kedarmp, very good catch, thanks. I updated the sed predicate to look for the exact word boundary \< \>

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