!directory.isDirectory() is an Android Studio problem that can have multiple reasons, e.g., it occurs when the file path of your project contains whitespaces. It can occur after renaming the package name as well. Solutions:
1. Check if there are any whitespaces in any folder of the whole file path. If so, remove the whitespaces from the folder’s name.
2. Remove the .gradle and .idea folders from the project directory and restart and reimport the Android Studio project. If you use macOS, you might need to enable the view of hidden files first (https://ianlunn.co.uk/articles/quickly-showhide-hidden-files-mac-os-x-mavericks).