Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

InjectionClient/Could not connect: Connection refused 🔥 #490

Closed
arthurschiller opened this issue Mar 5, 2024 · 18 comments
Closed

InjectionClient/Could not connect: Connection refused 🔥 #490

arthurschiller opened this issue Mar 5, 2024 · 18 comments

Comments

@arthurschiller
Copy link

Hi,

I finally wanted to implement Injection into my workflow. I think I've followed all the steps from readme but every time in run my project I get this console message:
InjectionClient/Could not connect: Connection refused 🔥 Unable to connect to InjectionIII app, falling back to standalone HotReloading.

Error loading /Applications/InjectionIII.app/Contents/Resources/iOSInjection.bundle/iOSInjection (82): dlopen(/Applications/InjectionIII.app/Contents/Resources/iOSInjection.bundle/iOSInjection, 0x0109): Symbol not found: _$sSS10SwiftTraceE11OffsetIndexO4lastyACSS_S2btcACmFWC

Here are the steps I've taken:

  1. Get InjectionIII App:
    https://github.com/johnno1962/InjectionIII/releases

2. Install Dependencies:
https://github.com/johnno1962/HotReloading
https://github.com/krzysztofzablocki/Inject

3. Add Linker (DEBUG) Flags:
-Xlinker and -interposable

4. Load Bundle on App Init
#if DEBUG
#if os(visionOS)
Bundle(path: "/Applications/InjectionIII.app/Contents/Resources/xrOSInjection.bundle")?.load()
#elseif targetEnvironment(macCatalyst)
Bundle(path: "/Applications/InjectionIII.app/Contents/Resources/macOSInjection.bundle")?.load()
#else
Bundle(path: "/Applications/InjectionIII.app/Contents/Resources/iOSInjection.bundle")?.load()
#endif
#endif

I've tested it with Xcode 15.2.0 and Xcode 15.3.0 Beta 2.
OS is Sonoma 14.1.2

It's probably something simple but I would appreciate any hints. Thank you!

@johnno1962
Copy link
Owner

Hi, the connection refused message is normal when you're not running the app. The other message happens when you have added the "HotReloading" Swift package at some point in the past and it picks up the wrong version of the SwiftTrace framework from derived data. You'll need to do a clean build to clear the wrong version out.

@arthurschiller
Copy link
Author

Hi, the connection refused message is normal when you're not running the app. The other message happens when you have added the "HotReloading" Swift package at some point in the past and it picks up the wrong version of the SwiftTrace framework from derived data. You'll need to do a clean build to clear the wrong version out.

Hi, thanks for the reply! What do you mean by "when you're not running the app"? Both the InjectionIII app and my projects app in the simulator are running and I selected the associated project directory.
I also tried resetting the Swift Package Manager Cache, cleaned the project, deleted Derived Data and restarted my machine. 🤔

@johnno1962
Copy link
Owner

johnno1962 commented Mar 5, 2024

Hmmm.. Remove https://github.com/johnno1962/HotReloading as a dependency. You either use that (rarely these days) or the app bundles. If you use both at the same time you get this error.

@arthurschiller
Copy link
Author

arthurschiller commented Mar 5, 2024

Hmmm.. Remove https://github.com/johnno1962/HotReloading as a dependency. You either use that (rarely these days) or the app bundles. If you use both at the same time you get this error.

Ah interesting, I saw a video where someone did both and it seemed to work, so I thought that's the way to go. What setup would you recommend? Primarily I would like to use it with the visionOS simulator, the actual Vision Pro device and with a Mac (Catalyst) app.

I tried removing the HotReloading dependency but that yields in the same error (connection refused). If I load the bundle manually I get:

`Error loading /Applications/InjectionIII.app/Contents/Resources/iOSInjection.bundle/iOSInjection (82):  dlopen(/Applications/InjectionIII.app/Contents/Resources/iOSInjection.bundle/iOSInjection, 0x0109): Symbol not found: _$sSS10SwiftTraceE11OffsetIndexO4lastyACSS_S2btcACmFWC
  Referenced from: <6E51BEA0-FB33-3620-9771-2B52DA5CF83E> /Applications/InjectionIII.app/Contents/Resources/iOSInjection.bundle/iOSInjection
  Expected in:     <B31C28E6-BD26-31E1-A706-046DFD36C763> /Users/<...>/Library/Developer/Xcode/DerivedData/SGMaterial_Playground-cmnrfbyrdzlqugfcvcotswsakavf/Build/Products/Debug-iphonesimulator/PackageFrameworks/SwiftTrace.framework/SwiftTrace`

Very odd. Xcode is installed via Xcodes app(https://www.xcodes.app) if that has any relevance.

@johnno1962
Copy link
Owner

Ignore the "connection refused" if you are not using the app. If you have removed the HotReloading Package did you perform a build clean afterwards? If you have a visionOS device I'd be very interested in knowing if you were able to get that working. There is a release candidate which should have support for that. I can talk you through that once you're up and running.

@arthurschiller
Copy link
Author

Ignore the "connection refused" if you are not using the app. If you have removed the HotReloading Package did you perform a build clean afterwards? If you have a visionOS device I'd be very interested in knowing if you were able to get that working. There is a release candidate which should have support for that. I can talk you through that once you're up and running.

Thanks for your help again! :) Got it running now in the Simulator after removing the HotReloading package and doing a clean build. Very cool!
I am a little confused though: There is the standalone app (which I assume I can just use as such), the Inject swift package and then the HotReloading package. Which should I use when? Or are they just different wrappers with the same goal?
Currently I have the Injection 3 App running and use the Inject Swift Package.

In this video he is importing both packages and it seems to work, which got me confused:
https://www.loom.com/share/c3331721a6ff47b9a66b30e7b59c6afc

Device injection (on iOS) seems to be working mostly but fails during loading of .dylib:
💉 Connecting to <…>...
💉 InjectionIII connected <…>
💉 Watching files under the directory <…>
💉 Compiling <…>
💉 Selecting Xcode /Applications/Xcode-15.3.0-Beta.2.app/Contents/Developer
💉 Loading .dylib ...
💉 ⚠️ dlopen() error: dlopen(/private/var/mobile/Containers/Data/Application/0E0C77D6-6DCF-4858-BA77-146AC2BC4573/tmp/eval101.dylib, 0x0002): tried: '/usr/lib/system/introspection/eval101.dylib' (no such file, not in dyld cache)

Yes, I have a visionOS device and would love to get it working there as well!

@arthurschiller
Copy link
Author

Update: Got it running now on my Mac and Vision Pro :)
I switched to the HotReloading Package instead of Inject though. But weirdly on my iPhone I still get this dlopen error:
🔥 ⚠️ dlopen() error: dlopen(/private/var/mobile/Containers/Data/Application/89D3960F-D1CF-46F5-A331-994FBB129419/tmp/eval102.dylib, 0x0002): tried: '/usr/lib/system/introspection/eval102.dylib' (no such file, not in dyld cache), '/private/var/mobile/Containers/Data/Application/89D3960F-D1CF-46F5-A331-994FBB129419/tmp/eval102.dylib' (code signature in <A0AFCA02-4C0E-319F-A389-D66F89DAA71C> '/private/var/mobile/Containers/Data/Application/89D3960F-D1CF-46F5-A331-994FBB129419/tmp/eval102.dylib' not valid for use in process: mapped file has no cdhash, completely unsigned? Code has to be at least ad-hoc signed.), '/private/preboot/Cryptexes/OS/private/var/mobile/Containers/Data/Application/89D3960F-D1CF-46F5-A331-994FBB129419/tmp/eval102.dylib' (no such file), '/private/var/mobile/Containers/Data/Application/89D3960F-D1CF-46F5-A331-994FBB129419/tmp/eval102.dylib' (code signature in <A0AFCA02-4C0E-319F-A389-D66F89DAA71C> '/private/var/mobile/Containers/Data/Application/89D3960F-D1CF-46F5-A331-994FBB129419/tmp/eval102.dylib' not valid for use in process: mapped file has no cdhash, completely unsigned? Code has to be at least ad-hoc signed.) 🔥 ⚠️ Injection error: Error Domain=SwiftEval Code=-1 "dlopen() error: dlopen(/private/var/mobile/Containers/Data/Application/89D3960F-D1CF-46F5-A331-994FBB129419/tmp/eval102.dylib, 0x0002): tried: '/usr/lib/system/introspection/eval102.dylib' (no such file, not in dyld cache),

@johnno1962
Copy link
Owner

We're making progress. There are a few moving part to injection and they evolve so it can be confusing. The original injection was The app performing the recompiling and the bundle doing the actual injection then I discovered the bundle could do it all in the simulator. For a real device, you can't load the bundle off your Mac's filesystem so the contents of the bundle are available in the HotReloading package. Then someone pointed out that you can copy a bundle into your app and load that instead of off the filesystem if you use the "copy_bundle.sh" script from the app's resources as a build phase.

I've just seen your new message. You're very nearly there using the HotReloading project which is fine. It's strange it's not seeing the dylib file but to my knowledge this is the first time someone has tried on an actual visionOS device. Do you have the option to zoom on this? I'd like to see this running if it's possible.

@johnno1962
Copy link
Owner

johnno1962 commented Mar 6, 2024

OK, so I've read your message properly now. You've got injection working on a Vision Pro! and now it doesn't work on a device? That is likely just a code signing problem. What configuration are you running at the moment? HotReloading on a device? I've checked it and can't see a problem on my machine at the moment.

@arthurschiller
Copy link
Author

OK, so I've read your message properly now. You've got injection working on a Vision Pro! and now it doesn't work on a device? That is likely just a code signing problem. What configuration are you running at the moment? HotReloading on a device? I've checked it and can't see a problem on my machine at the moment.

Hi, so it's working on all the Simulators, my Mac and my Vision Pro (on device 🎊). The only time where I'm now getting this issue is on my physical iPhone 14 Pro device. Xcode Beta 15.3.0, Sonoma 14.1.2

I also now removed the HotReloading package and opted for just loading everything manually using the code generated by the Injection app when selecting -> Prepare Project
Still runs fine, only issue left is the dlopen (only!) on the physical iPhone device.

@arthurschiller
Copy link
Author

Interestingly enough, on the physical Vision Pro device I could load the iOSInjection bundle and it still worked. Probably similar enough ->

// Running on Real Device let resourceName: String #if os(macOS) || targetEnvironment(macCatalyst) resourceName = "macOSInjection" #elseif os(visionOS) resourceName = "iOSInjection" // seems to work without using xrOSInjection #else resourceName = "iOSInjection" #endif guard let bundlePath = Bundle.main.path(forResource: resourceName, ofType: "bundle"), let bundle = Bundle(path: bundlePath), bundle.load() else { fatalError() }

@johnno1962
Copy link
Owner

johnno1962 commented Mar 6, 2024

Very, very weird about the bundles. Where is that code you pasted in coming from?

And visionOS is actually injecting now? That would be awesome! Not sure what's happening on the iOS device. I've seen the error you're seeing today whereas it's worked before. Trying to factor out between new Xcode, new iOS version, changes to InjectionIII etc. It should be code signing correctly.

@arthurschiller
Copy link
Author

arthurschiller commented Mar 6, 2024

Very, very weird about the bundles. Where is that code you pasted in coming from?

And visionOS is actually injecting now? That would be awesome! Not sure what's happening on the iOS device. I've seen the error you're seeing today whereas it's worked before. Trying to factor out between new Xcode, new iOS version, changes to InjectionIII etc. It should be code signing correctly.

Here is the helper snippet I'm using (collected from a couple different sources, mostly "Prepare Project" helper):
https://gist.github.com/arthurschiller/a4471129584d11e9b358d99bad4aa0dc

Yeah visionOS works totally fine :)
Video attached:
https://github.com/johnno1962/InjectionIII/assets/3637723/0d38006a-a4f2-49d0-b881-2582abc5c357

I can try it maybe with another iPhone.

@johnno1962
Copy link
Owner

Found the silly problem due to renaming a file which was taking out code signing and I'll release a new release candidate this evening. Thanks for checking all these things out!

@arthurschiller
Copy link
Author

Found the silly problem due to renaming a file which was taking out code signing and I'll release a new release candidate this evening. Thanks for checking all these things out!

Awesome, thanks so much for this project! Already seeing how this will greatly accelerate my workflow :)

@johnno1962
Copy link
Owner

johnno1962 commented Mar 6, 2024

I've updated the release candidate with this fix. You should find on-iOS device injection is working again. Thanks for the link to @gonchar's excellent video. I had no idea people had already got injection working on a visionOS device (as it should!)

@arthurschiller
Copy link
Author

I've updated the release candidate with this fix. You should find on-iOS device injection is working again. Thanks for the link to @gonchar's excellent video. I had no idea people had already got injection working on a visionOS device (as it should!)

Excellent, that did the trick! Thanks so much! :)

@johnno1962
Copy link
Owner

Thanks for raising the issue. It cleared up all sorts of things :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants