Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Discussion options

Hi,

I read the documentation regarding previews in Xcode and here is what I got:

Dual-Platform Apps
Assuming you followed the app creation instructions using skip init, each successful build of your Skip app will automatically attempt to launch it on the running Android emulator or device. Exactly one emulator or device must be running in order for the Skip project’s Launch APK script phase to install and run the app successfully.
If you are having trouble with Skip’s Xcode plugin, check the Troubleshooting section for help.
Xcode Previews will not work in Skip apps until you have performed one full build. After an initial successful build, you can iterate using Previews.

But I am still having trouble with running the previews. I made a full build as the documentation says, but the preview will never load and the android app will keep reloading.

You must be logged in to vote

The problem is discussed at https://developer.apple.com/forums/thread/761439: Xcode no longer sets the ENABLE_PREVIEWS environment variable for SwiftUI previews, which is the only way we have to prevent running the skip gradle Xcode build phase command that handles the compile/launch on Android. Toggling the "Editor > Canvas > Use Legacy Previews Execution" menu item should work around the issue for now, but note that that setting will be reset every time Xcode upgrades, so you will need to re-enable it every time there is an update.

The other solution is to just comment-out the "skip gradle" command in the "Run skip gradle" build script when you are developing with SwiftUI previews, and …

Replies: 11 comments · 12 replies

Comment options

Yes, I'm seeing similar Canvas/Preview makes the Android device reload the App. I don't understand the tie in ... I know Xcode does a build for the preview and the simulator device when one opens the Canvas. Don't know why the Gradle/Android build would get involved.

You must be logged in to vote
0 replies
Comment options

What version of Xcode are you running?

You must be logged in to vote
0 replies
Comment options

Xcode Version 16.0 (16A242d)

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

Can you take a look at your app's target's "Build Phases" tab and examine the "Run skip gradle" phase to ensure that it looks like this:

Screenshot 2024-10-17 at 12 41 59

This is something that is created when the app is first initialized, and so if you created it a while ago (before this check was added), then it might not have been added.

FTR, the complete "Run skip gradle" script should look like:

if [ "${SKIP_ZERO}" != "" ]; then
	echo "note: skipping skip due to SKIP_ZERO"
	exit 0
elif [ "${ENABLE_PREVIEWS}" == "YES" ]; then
	echo "note: skipping skip due to ENABLE_PREVIEWS"
	exit 0
elif [ "${ACTION}" == "install" ]; then
	echo "note: skipping skip due to archive install"
	exit 0
else
	SKIP_ACTION="${SKIP_ACTION:-launch}"
fi
PATH=${BUILD_ROOT}/Debug:${BUILD_ROOT}/../../SourcePackages/artifacts/skip/skip/skip.artifactbundle/macos:${PATH}:${HOMEBREW_PREFIX:-/opt/homebrew}/bin
echo "note: running gradle build with: $(which skip) gradle -p ${PWD}/../Android ${SKIP_ACTION:-launch}${CONFIGURATION:-Debug}"
skip gradle -p ../Android ${SKIP_ACTION:-launch}${CONFIGURATION:-Debug}

FWIW, previews work for me in Xcode 16 with the default "Hello Skip" app (created with skip init --open-xcode --appid=com.xyz.HelloSkip hello-skip HelloSkip and then adding the #Preview block).

Screenshot 2024-10-17 at 12 41 03
You must be logged in to vote
0 replies
Comment options

Didn't want to do this, but I just cleaned everything by deleting the project and recloning my GitHub repo.

@davidakoontz might be of help.

You must be logged in to vote
2 replies
@marcprux
Comment options

Does the Preview work for you now? Did you try my suggestion?

@arshmeets
Comment options

Appreciate your suggestion. Tried the android Run skip gradle code which I hadn't changed since the start of making my project so didn't make a difference there and the #Preview suggestion also didn't work. Still had the issue of the android app restarting so I decided to clean and repull repo from Github

Comment options

You must be logged in to vote
0 replies
Comment options

weird the images didn't transmit... it's going to be one of THOSE days...

Trying again... WITH FEELING...

Screenshot 2024-10-17 at 12 51 53 PM Screenshot 2024-10-17 at 12 53 05 PM
You must be logged in to vote
2 replies
@davidakoontz
Comment options

Not sure what you suggestion was - tell me again. @marcprux

@arshmeet-s
Comment options

The suggestion was to check the build code as you've done. Have you tried my solution of cleaning everything and pulling your github repo? First make sure that you have a github repo btw.

Comment options

You must be logged in to vote
0 replies
Comment options

The problem is discussed at https://developer.apple.com/forums/thread/761439: Xcode no longer sets the ENABLE_PREVIEWS environment variable for SwiftUI previews, which is the only way we have to prevent running the skip gradle Xcode build phase command that handles the compile/launch on Android. Toggling the "Editor > Canvas > Use Legacy Previews Execution" menu item should work around the issue for now, but note that that setting will be reset every time Xcode upgrades, so you will need to re-enable it every time there is an update.

The other solution is to just comment-out the "skip gradle" command in the "Run skip gradle" build script when you are developing with SwiftUI previews, and then just remember to re-enable it the next time you need to launch on Android.

Important

We encourage anyone encountering this issue to chime in on the thread mentioned above to try to elicit a less unsatisfactory long-term solution, as well as to file a Feedback Assistant issue referencing FB16424982.

You must be logged in to vote
5 replies
@davidakoontz
Comment options

Thank you for the explaination ( the apple link ). Had to search for the - suggested workaround: "Use legacy preview execution"

Screenshot 2024-10-30 at 12 25 42 PM

Look in Xcode > Editor > Canvas (2nd entry) then bottom of that 2nd Canvas menu > Use legacy...

@davidakoontz
Comment options

Love having my Previews back!! Thanks Marc!

I must have missed the memo from Apple...

@timkoss
Comment options

I am on Xcode 16.2 and I don't have the 2nd Canvas item. I can't fine the Legacy Previews anywhere. Any ideas?

image

@timkoss
Comment options

Just reading more and I found this:

In Xcode 16.2, Apple removed the Legacy Previews Execution option as it continues to refine SwiftUI previews. If you're having trouble with SwiftUI previews or need a similar behavior to the old Legacy mode, here are some options to troubleshoot and adjust your development environment:

Any other solutions to this problem?

@JeffFlowerday
Comment options

Xcode 26.2 has Legacy Previews Execution back. Or maybe it returned in an earlier 26.x release.

Answer selected by marcprux
Comment options

You must be logged in to vote
3 replies
@timkoss
Comment options

Thanks. I did roll back to 16.1 and that solves the problem. Hopefully there will be a long term solution

@marcprux
Comment options

I opened a TSI with Apple last week to see if they have a solution. As it stands right now, it is unfortunately impossible to use SwiftUI #Previews along with the default build script that Skip uses to launch the app in 6.2 due to their removal of the "Legacy Previews Execution" option.

@marcprux
Comment options

Note that "Legacy Previews Execution" does sometimes work in 16.2, but other times it is disabled. We're not yet sure the conditions under which the option is available.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
🙏
Q&A
Labels
None yet
6 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.