johnno1962 / InjectionNext

Fourth evolution of Code Injection for Xcode
MIT License
47 stars 1 forks source link

Transition from InjectionIII + crashing #3

Closed paul-brenner closed 1 month ago

paul-brenner commented 1 month ago

I'm trying to transition from InjectionIII, mainly because it has been crashing my app constantly.

I open InjectionNext, use it to Launch Xcode, then do a clean build. But I still see in my logs:

💉 Unable to connect to InjectionIII app, falling back to standalone HotReloading.
InjectionClient/Could not connect: Connection refused
💉 Standalone InjectionIII available for sources under ["/Users/paul"]

How do I convince it to stop looking for InjectionIII? Is that message coming from HotSwiftUI (1.1.8)?

I'm not sure if I'm missing a setup guide that should tell me what I'm doing wrong or if InjectionNext isn't ready for users like me who need that kind of hand holding.

johnno1962 commented 1 month ago

Hi, are you still loading the iOSInjection.bundle somewhere? If you've added the InjectionNext package you shouldn't be seeing this message. Can you tell me more about the "crashing your app" though. Which InjectionIII version was that? Have you tried reverting to an older version. InjectionNext is still a little fresh but ideally both should be working at this stage!

paul-brenner commented 1 month ago

When I search my codebase I don't see iOSInjection.bundle anywhere. If I search for "injection" I just get a bunch of hits for @ObserveInjection var redraw and .enableInjection() the only code I can find that is related is @_exported import HotSwiftUI

I'm struggling to think where else I could have set it to make it look or InjectionIII?

The crashes have been with InjectionIII 5.0.1 (which you provided here https://github.com/johnno1962/InjectionIII/issues/506). If I change anything and save a file, it recompiles then crashes on an async function somewhere (seems like the crashes are random). I saw you suggested to someone setting INJECTION_PRESERVE_STATICS to YES, which I thought might help in my case (all those async functions depend on having a global supabase client class).

I was hoping if I could get a clean setup with InjectionNext then next step I could start debugging those crashes better, but at the moment I think my setup is still trying to use InjectionIII

johnno1962 commented 1 month ago

This is all useful information. In HotSwiftUI when you call .enableInjection() it will load one of the bundles for you but that should be disabled by the presence of an InjectionClient @objc class one of which is provided by the InjectionNext Swift Package. Injection mixed with async functions is uncharted territory and it may be best not to try to inject them but you're right it will be much easier to debug and iterate over if you persist in the switch to InjectionNext which is almost the same code. Can you summarise your project? You have added InjectionNext and HotSwiftUI Swift packages and have the injectionIII app installed but you're running the InjectionNext app instead (to launch Xcode)?

johnno1962 commented 1 month ago

The relevant code in HotSwiftUI (there isn't much to it) is here.

paul-brenner commented 1 month ago

Yes, this describes the situation exactly: "You have added InjectionNext and HotSwiftUI Swift packages and have the injectionIII app installed but you're running the InjectionNext app instead (to launch Xcode)?"

I haven't gone as far as Prepare swiftui -> entire project yet.

Ah, as I was typing this I checked the Link Binary With Libraries for my Target and found that InjectionNext was only added to the project and not there for my target. Now it is loading injection next:

đŸ”Ĩ InjectionNext: iPhoneSimulator connection to app established, waiting for commands.
đŸ”Ĩ Platform connected: iPhoneSimulator
paul-brenner commented 1 month ago

I'll check if this helps with the crashes i've been seeing and report back, though I'm surprised that I immediately just hit:

/Users/paul/Siv/siv-ios/Siv/Siv/Features/Share/ActivityLog.swift:12:16: error: external macro implementation type 'SwiftDataMacros.QueryMacro' could not be found for macro 'Query()'
    @Query var activityEntries: [ActivityLogEntrySD]

and I'm assuming support for swiftdata won't be on the roadmap anytime soon.

johnno1962 commented 1 month ago

Yeah, that's a bit of a gotcha alas. It seems to be getting easier to not get it right with each release of Xcode. You should be up and running now the load is being inhibited.

johnno1962 commented 1 month ago

I'll be looking at the macros problem when I get back to my machine #4, core data I can't comment on unless there is a small example project I could look at. It needn't not work.

johnno1962 commented 1 month ago

I've uploaded a new version of the app where this macros problem should be resolved if you want to give it a try. Let me know how you get on with SwiftData.

paul-brenner commented 1 month ago

Macros problem is fixed and I'm not seeing crashing anymore. I've even got hot reloading working on some simpler views!

I do run into a different problem, most of the time with this error:

đŸ”Ĩ Injection failed to load. If this was due to a default argument. Select the app's menu item "Unhide Symbols".
đŸ”Ĩ ⚠ī¸ dlopen failed dlopen(/Users/paul/Library/Developer/CoreSimulator/Devices/F16469C4-F7D9-4403-979C-390667F3863C/data/Containers/Data/Application/35084EAC-3356-4293-9D5F-3CF332465B06/tmp//eval_injection_SettingsView_9.dylib, 0x0002): symbol not found in flat namespace '_$s4Auth4UserV2id11appMetadata04userE03aud18confirmationSentAt08recoveryiJ0011emailChangeiJ08newEmail07invitedJ010actionLink0L05phone07createdJ009confirmedJ00l9ConfirmedJ00svJ0010lastSignInJ04role07updatedJ010identities11isAnonymous7factorsAC10Foundation4UUIDV_SDySS7Helpers7AnyJSONOGA4_SSAZ4DateVSgA7_A7_SSSgA7_A8_A8_A8_A6_A7_A7_A7_A7_A8_A6_SayAA0B8IdentityVGSgSbSayAA6FactorVGSgtcfcfA19_'
đŸ”Ĩ ℹī¸ Symbol not found during load. Unfortunately, sometimes it is not possible to inject code that implies a default argument when calling a function. Make the value explicit and this should work. The argument omitted was: default argument 20 of Auth.User.init(id: Foundation.UUID, appMetadata: Swift.Dictionary<Swift.String, Helpers.AnyJSON>, userMetadata: Swift.Dictionary<Swift.String, Helpers.AnyJSON>, aud: Swift.String, confirmationSentAt: Swift.Optional<Foundation.Date>, recoverySentAt: Swift.Optional<Foundation.Date>, emailChangeSentAt: Swift.Optional<Foundation.Date>, newEmail: Swift.Optional<Swift.String>, invitedAt: Swift.Optional<Foundation.Date>, actionLink: Swift.Optional<Swift.String>, email: Swift.Optional<Swift.String>, phone: Swift.Optional<Swift.String>, createdAt: Foundation.Date, confirmedAt: Swift.Optional<Foundation.Date>, emailConfirmedAt: Swift.Optional<Foundation.Date>, phoneConfirmedAt: Swift.Optional<Foundation.Date>, lastSignInAt: Swift.Optional<Foundation.Date>, role: Swift.Optional<Swift.String>, updatedAt: Foundation.Date, identities: Swift.Optional<Swift.Array<Auth.UserIdentity>>, isAnonymous: Swift.Bool, factors: Swift.Optional<Swift.Array<Auth.Factor>>) -> Auth.User.
đŸ”Ĩ Injection failed to load. If this was due to a default argument. Select the app's menu item "Unhide Symbols".

I'm trying to think about whether there is a workaround that I can throw at this for development. Not sure why I didn't have this problem before, but it doesn't really related to the original subject of this issue so I can close if that makes most sense.

johnno1962 commented 1 month ago

20th default argument eh? That's really pushing the boundaries though it should work. Did you use the menu item "Unhide Symbols" restart your app and try again?

paul-brenner commented 1 month ago

I'm going to close this. I still run into weird behavior sometime and I keep thinking I'm going to be able to capture get it into a reproducible and explainable state that I can describe but it hasn't happened yet. Regardless, InjectionNext is working often enough and well enough that it is back to being an indispensable part of my workflow. I love it.