Hi everyone, Your SwiftUI Preview are not working ...
# ios
f
Hi everyone, Your SwiftUI Preview are not working well or slow because of infinite Gradle build Framework task? The solution : Check for change inside your shared Kotlin source to avoid useless build! Working only if you’re building a dynamic framework
Copy code
CUR="${SRCROOT}/../shared/build/list_of_files.txt"
OLD="${SRCROOT}/../shared/build/old_list_of_files.txt"
touch $OLD
CHANGES="${SRCROOT}/../shared/build/list_of_changes.txt"

ls -lRT "${SRCROOT}/../shared/src/" > $CUR
diff $OLD $CUR > $CHANGES

if [ ! -s "${CHANGES}" ]; then
  echo "No change in shared source"
  exit 0
fi


if [ "YES" = "$OVERRIDE_KOTLIN_BUILD_IDE_SUPPORTED" ]; then
 echo "Skipping Gradle build task invocation due to OVERRIDE_KOTLIN_BUILD_IDE_SUPPORTED environment variable set to \"YES\""
 exit 0
fi
cd "$SRCROOT/.."
./gradlew :shared:embedAndSignAppleFrameworkForXcode

# set the current change as old after the build is OK
mv $CUR $OLD
😮 2
👍 2
After some usage, the script is incomplete and needs to be adapted depending on your project structure. But the logic still remains the same; don’t trigger the task if there is no change.