johnno1962 / InjectionIII

Re-write of Injection for Xcode in (mostly) Swift
MIT License
4.07k stars 319 forks source link

dlopen() error: Library not loaded: @rpath/libswift_Concurrency.dylib #506

Closed paul-brenner closed 4 months ago

paul-brenner commented 5 months ago

After a few hours of trying, I can't seem to figure out what I have configured incorrectly.

I'm using InjectIII 5.0 and HotSwiftUI installed via SPM and have for my ios target Other Linker Flag->Debug set to -Xlinker and -interposable (no quotes separate lines). But I always run into this error:

🔥 showLocationOnCategorySelection #1 (category: Swift.String) -> () in Siv.MySivsView.filterSection.getter : some is private and may not inject
🔥 Loading .dylib ...
🔥 ⚠️ dlopen() error: dlopen(/Users/paul/Library/Developer/CoreSimulator/Devices/F16469C4-F7D9-4403-979C-390667F3863C/data/Containers/Data/Application/ACDBB948-9061-47A9-85B2-E69EBC549E24/tmp/eval101.dylib, 0x0002): Library not loaded: @rpath/libswift_Concurrency.dylib
  Referenced from: <0A0032EA-875E-3E25-A53D-995893C02FD2> /Users/paul/Library/Developer/CoreSimulator/Devices/F16469C4-F7D9-4403-979C-390667F3863C/data/Containers/Data/Application/ACDBB948-9061-47A9-85B2-E69EBC549E24/tmp/eval101.dylib
  Reason: tried: '/Users/paul/Library/Developer/Xcode/DerivedData/Siv-gcyyqfuiqnspnmeimxcssicloaab/Build/Products/Debug-iphonesimulator/libswift_Concurrency.dylib' (no such file), '/Library/Developer/CoreSimulator/Volumes/iOS_21E213/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 17.4.simruntime/Contents/Resources/RuntimeRoot/usr/lib/system/introspection/libswift_Concurrency.dylib' (no such file), '/Library/Developer/CoreSimulator/Volumes/iOS_21E213/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 17.4.simruntime/Contents/Resources/RuntimeRoot/Users/paul/Library/Developer/CoreSimulator/Devices/F16469C4-F7D9-4403-979C-390667F3863C/data/Containers/Bundle/Application/FE33F77B-CDDC-4B5A-93D6-EF10F1A370F0/Siv.app/Frameworks/libswift_Concurrency.dylib' (no such file), '/Users/paul/Library/Developer/CoreSimulator/Devices/F16469C4-F7D9-4403-979C-390667F3863C/data/Containers/Bundle/Application/FE33F77B-CDDC-4B5A-93D6-EF10F1A370F0/Siv.app/Frameworks/libswift_Concurrency.dylib' (no such file), '/Library/Developer/CoreSimulator/Volumes/iOS_21E213/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 17.4.simruntime/Contents/Resources/RuntimeRoot/Users/paul/Library/Developer/CoreSimulator/Devices/F16469C4-F7D9-4403-979C-390667F3863C/data/Containers/Bundle/Application/FE33F77B-CDDC-4B5A-93D6-EF10F1A370F0/Siv.app/Frameworks/libswift_Concurrency.dylib' (no such file), '/Users/paul/Library/Developer/CoreSimulator/Devices/F16469C4-F7D9-4403-979C-390667F3863C/data/Containers/Bundle/Application/FE33F77B-CDDC-4B5A-93D6-EF10F1A370F0/Siv.app/Frameworks/libswift_Concurrency.dylib' (no such file), '/Library/Developer/CoreSimulator/Volumes/iOS_21E213/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 17.4.simruntime/Contents/Resources/RuntimeRoot/Users/paul/Library/Developer/Xcode/DerivedData/Siv-gcyyqfuiqnspnmeimxcssicloaab/Build/Products/Debug-iphonesimulator/PackageFrameworks/libswift_Concurrency.dylib' (no such file), '/Users/paul/Library/Developer/Xcode/DerivedData/Siv-gcyyqfuiqnspnmeimxcssicloaab/Build/Products/Debug-iphonesimulator/PackageFrameworks/libswift_Concurrency.dylib' (no such file), '/Users/paul/Library/Developer/CoreSimulator/Devices/F16469C4-F7D9-4403-979C-390667F3863C/data/Containers/Bundle/Application/FE33F77B-CDDC-4B5A-93D6-EF10F1A370F0/Siv.app/Frameworks/libswift_Concurrency.dylib' (no such file), '/Users/paul/Library/Developer/CoreSimulator/Devices/F16469C4-F7D9-4403-979C-390667F3863C/data/Containers/Bundle/Application/FE33F77B-CDDC-4B5A-93D6-EF10F1A370F0/Siv.app/libswift_Concurrency.dylib' (no such file), '/Library/Developer/CoreSimulator/Volumes/iOS_21E213/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 17.4.simruntime/Contents/Resources/RuntimeRoot/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/15.0.0/lib/darwin/libswift_Concurrency.dylib' (no such file), '/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/15.0.0/lib/darwin/libswift_Concurrency.dylib' (no such file), '/Library/Developer/CoreSimulator/Volumes/iOS_21E213/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 17.4.simruntime/Contents/Resources/RuntimeRoot/usr/lib/libswift_Concurrency.dylib' (no such file)

I can't think of anything in my project that uses libswift_Concurrency.dylib explicitly, though I suppose it could be related to one of the packages.

johnno1962 commented 5 months ago

Hi, what version of Xcode is this? I'll look at modifying the "rpath" of the injection bundle to cater for this but in the meantime you should be able to add a Debug config "rpath" (Runpath Search Paths build setting) to your app of: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift-5.5/iphoneos. Any chance you have a small example program that replicates this problem I can look at?

paul-brenner commented 5 months ago

This is on Xcode 15.4. I can confirm that adding the Debug config rpath as you suggested fixes it.

So far I'm failing to create a small example program that replicates, when I strip my app down to the bare bones I seem to be also stripping out whatever is causing the problem. Happy to try to do whatever else might help if there is anything else?

johnno1962 commented 5 months ago

Never mind about a replicator as this is a small change. I'll push a new release candidate if you could test if later today.

paul-brenner commented 5 months ago

thanks! will do.

johnno1962 commented 5 months ago

Sorry, I can't upload a release candidate today as @GitHub seems to be broken. Will try again later.

johnno1962 commented 5 months ago

I've been able to upload the new pre-release using an old version of Safari 🤷‍♂️. When you get a chance can you try it out with your rpath override removed? https://github.com/johnno1962/InjectionIII/releases/tag/5.0.1RC1

paul-brenner commented 5 months ago

wow! Tested and confirmed working. Thank you!

johnno1962 commented 5 months ago

👍

paul-brenner commented 5 months ago

Just a heads up that if I build on the simulator and just leave it sitting there I'll see the same errors filling up my logs:

💉 ⚠️ dlopen() error: dlopen(/Users/paul/Library/Developer/CoreSimulator/Devices/F16469C4-F7D9-4403-979C-390667F3863C/data/Containers/Data/Application/F3B0C177-1985-4929-A02A-D6D3D01FA48D/tmp/eval101.dylib, 0x0002): Library not loaded: @rpath/libswift_Concurrency.dylib
  Referenced from: <52B1B6AE-5ADD-3E33-A130-C2765181A296> /Users/paul/Library/Developer/CoreSimulator/Devices/F16469C4-F7D9-4403-979C-390667F3863C/data/Containers/Data/Application/F3B0C177-1985-4929-A02A-D6D3D01FA48D/tmp/eval101.dylib
  Reason: tried: '/Users/paul/Library/Developer/Xcode/DerivedData/Siv-gcyyqfuiqnspnmeimxcssicloaab/Build/Products/Debug-iphonesimulator/libswift_Concurrency.dylib' (no such file), '/Library/Developer/CoreSimulator/Volumes/iOS_21E213/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 17.4.simruntime/Contents/Resources/RuntimeRoot/usr/lib/system/introspection/libswift_Concurrency.dylib' (no such file), '/Library/Developer/CoreSimulator/Volumes/iOS_21E213/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 17.4.simruntime/Contents/Resources/RuntimeRoot/Users/paul/Library/Developer/CoreSimulator/Devices/F16469C4-F7D9-4403-979C-390667F3863C/data/Containers/Data/Application/F3B0C177-1985-4929-A02A-D6D3D01FA48D/tmp/libswift_Concurrency.dylib' (no such file), '/Users/paul/Library/Developer/CoreSimulator/Devices/F16469C4-F7D9-4403-979C-390667F3863C/data/Containers/Data/Application/F3B0C177-1985-4929-A02A-D6D3D01FA48D/tmp/libswift_Concurrency.dylib' (no such file), '/Library/Developer/CoreSimulator/Volumes/iOS_21E213/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 17.4.simruntime/Contents/Resources/RuntimeRoot/Users/paul/Library/Developer/CoreSimulator/Devices/F16469C4-F7D9-4403-979C-390667F3863C/data/Containers/Data/Application/F3B0C177-1985-4929-A02A-D6D3D01FA48D/tmp/libswift_Concurrency.dylib' (no such file), '/Users/paul/Library/Developer/CoreSimulator/Devices/F16469C4-F7D9-4403-979C-390667F3863C/data/Containers/Data/Application/F3B0C177-1985-4929-A02A-D6D3D01FA48D/tmp/libswift_Concurrency.dylib' (no such file), '/Library/Developer/CoreSimulator/Volumes/iOS_21E213/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 17.4.simruntime/Contents/Resources/RuntimeRoot/Users/paul/Library/Developer/Xcode/DerivedData/Siv-gcyyqfuiqnspnmeimxcssicloaab/Build/Products/Debug-iphonesimulator/PackageFrameworks/libswift_Concurrency.dylib' (no such file), '/Users/paul/Library/Developer/Xcode/DerivedData/Siv-gcyyqfuiqnspnmeimxcssicloaab/Build/Products/Debug-iphonesimulator/PackageFrameworks/libswift_Concurrency.dylib' (no such file), '/Users/paul/Library/Developer/CoreSimulator/Devices/F16469C4-F7D9-4403-979C-390667F3863C/data/Containers/Bundle/Application/87409E6B-5F37-428F-A87D-0F972D7E095C/Siv.app/Frameworks/libswift_Concurrency.dylib' (no such file), '/Users/paul/Library/Developer/CoreSimulator/Devices/F16469C4-F7D9-4403-979C-390667F3863C/data/Containers/Bundle/Application/87409E6B-5F37-428F-A87D-0F972D7E095C/Siv.app/libswift_Concurrency.dylib' (no such file), '/Library/Developer/CoreSimulator/Volumes/iOS_21E213/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 17.4.simruntime/Contents/Resources/RuntimeRoot/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/15.0.0/lib/darwin/libswift_Concurrency.dylib' (no such file), '/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/15.0.0/lib/darwin/libswift_Concurrency.dylib' (no such file), '/Library/Developer/CoreSimulator/Volumes/iOS_21E213/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 17.4.simruntime/Contents/Resources/RuntimeRoot/usr/lib/libswift_Concurrency.dylib' (no such file)

But then as soon as I go into a file with @ObserveInjection var redraw and make changes it happily shows

💉 Compiling /Users/paul/Siv/siv-ios/Siv/Siv/Features/Main/CustomTabBar.swift
💉 Loading .dylib ...
💉 Interposed 20 function references.
💉 Injected type #1 'Siv.CustomTabBar'
💉 Injected type #2 'Siv.CustomTabItem'

then works as expected. So very much working for me, but I imagine if a new user setting up sees those messages they may not realize that everything will still work.

johnno1962 commented 5 months ago

Yeah that's weird. Xcode autosaves files from time to time which would trigger an injection. Does it tell you what file it's recompiling? Does that make sense? I don't know what sort of file would cause the problem to come back though.

paul-brenner commented 5 months ago

Ah I see that Inject just conveniently told me:

💉 Compiling /Users/paul/Siv/siv-ios/Siv/Siv/Data/SivRepository.swift
💉 Loading .dylib ...
💉 ⚠️ dlopen() error: dlopen(/Users/paul/Library/Developer/CoreSimulator/Devices/F16469C4-F7D9-4403-979C-390667F3863C/data/Containers/Data/Application/C56500DC-6F79-477C-9786-752ED701A3C0/tmp/eval107.dylib, 0x0002): Library not loaded: @rpath/libswift_Concurrency.dylib

but that file is purely backend. I can put it up temporarily here if that is helpful at all.

paul-brenner commented 5 months ago

Not sure how much this is a problem worth fixing for everyone or just a problem unique to me but it is broken again for reasons I can't figure out:

💉 ⚠️ dlopen() error: dlopen(/Users/paul/Library/Developer/CoreSimulator/Devices/F16469C4-F7D9-4403-979C-390667F3863C/data/Containers/Data/Application/B9E97AC2-D606-43F9-9A92-7E46922738BD/tmp/eval101.dylib, 0x0002): Library not loaded: @rpath/libswift_Concurrency.dylib
  Referenced from: <3A8C3243-90E6-3765-A159-C63D18E39C49> /Users/paul/Library/Developer/CoreSimulator/Devices/F16469C4-F7D9-4403-979C-390667F3863C/data/Containers/Data/Application/B9E97AC2-D606-43F9-9A92-7E46922738BD/tmp/eval101.dylib
  Reason: tried: '/Users/paul/Library/Developer/Xcode/DerivedData/Siv-gcyyqfuiqnspnmeimxcssicloaab/Build/Products/Debug-iphonesimulator/libswift_Concurrency.dylib' (no such file), '/Library/Developer/CoreSimulator/Volumes/iOS_21E213/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 17.4.simruntime/Contents/Resources/RuntimeRoot/usr/lib/system/introspection/libswift_Concurrency.dylib' (no such file), '/Library/Developer/CoreSimulator/Volumes/iOS_21E213/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 17.4.simruntime/Contents/Resources/RuntimeRoot/Users/paul/Library/Developer/CoreSimulator/Devices/F16469C4-F7D9-4403-979C-390667F3863C/data/Containers/Data/Application/B9E97AC2-D606-43F9-9A92-7E46922738BD/tmp/libswift_Concurrency.dylib' (no such file), '/Users/paul/Library/Developer/CoreSimulator/Devices/F16469C4-F7D9-4403-979C-390667F3863C/data/Containers/Data/Application/B9E97AC2-D606-43F9-9A92-7E46922738BD/tmp/libswift_Concurrency.dylib' (no such file), '/Library/Developer/CoreSimulator/Volumes/iOS_21E213/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 17.4.simruntime/Contents/Resources/RuntimeRoot/Users/paul/Library/Developer/CoreSimulator/Devices/F16469C4-F7D9-4403-979C-390667F3863C/data/Containers/Data/Application/B9E97AC2-D606-43F9-9A92-7E46922738BD/tmp/libswift_Concurrency.dylib' (no such file), '/Users/paul/Library/Developer/CoreSimulator/Devices/F16469C4-F7D9-4403-979C-390667F3863C/data/Containers/Data/Application/B9E97AC2-D606-43F9-9A92-7E46922738BD/tmp/libswift_Concurrency.dylib' (no such file), '/Library/Developer/CoreSimulator/Volumes/iOS_21E213/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 17.4.simruntime/Contents/Resources/RuntimeRoot/Users/paul/Library/Developer/Xcode/DerivedData/Siv-gcyyqfuiqnspnmeimxcssicloaab/Build/Products/Debug-iphonesimulator/PackageFrameworks/libswift_Concurrency.dylib' (no such file), '/Users/paul/Library/Developer/Xcode/DerivedData/Siv-gcyyqfuiqnspnmeimxcssicloaab/Build/Products/Debug-iphonesimulator/PackageFrameworks/libswift_Concurrency.dylib' (no such file), '/Library/Developer/CoreSimulator/Volumes/iOS_21E213/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 17.4.simruntime/Contents/Resources/RuntimeRoot/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift-5.5/iphoneos/libswift_Concurrency.dylib' (no such file), '/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift-5.5/iphoneos/libswift_Concurrency.dylib' (mach-o file (/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift-5.5/iphoneos/libswift_Concurrency.dylib), but incompatible platform (have 'iOS', need 'iOS-sim')), '/Users/paul/Library/Developer/CoreSimulator/Devices/F16469C4-F7D9-4403-979C-390667F3863C/data/Containers/Bundle/Application/3245320F-0413-4130-B738-5D23BAC93BCD/Siv.app/Frameworks/libswift_Concurrency.dylib' (no such file), '/Users/paul/Library/Developer/CoreSimulator/Devices/F16469C4-F7D9-4403-979C-390667F3863C/data/Containers/Bundle/Application/3245320F-0413-4130-B738-5D23BAC93BCD/Siv.app/libswift_Concurrency.dylib' (no such file), '/Library/Developer/CoreSimulator/Volumes/iOS_21E213/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 17.4.simruntime/Contents/Resources/RuntimeRoot/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/15.0.0/lib/darwin/libswift_Concurrency.dylib' (no such file), '/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/15.0.0/lib/darwin/libswift_Concurrency.dylib' (no such file), '/Library/Developer/CoreSimulator/Volumes/iOS_21E213/Library/Developer/CoreSimulator/Profiles/Runtimes/iOS 17.4.simruntime/Contents/Resources/RuntimeRoot/usr/lib/libswift_Concurrency.dylib' (no such file)
💉 ⚠️ Clean build folder when switching platform

This is when I save a file that actually is a view and right after cleaning the build folder.

johnno1962 commented 5 months ago

Hi Paul, not sure what's happening there. I assume you tried the "Runtime Search paths" fix? If you can hang tight for a bit there is something new in the pipeline that can be worked on more easily.

paul-brenner commented 5 months ago

Sounds good! I'll keep working with it and see if I can figure anything out in the mean time. Now that I've tried InjectionIII, I can't imagine going back to the old way, even with the errors I'm hitting.

johnno1962 commented 5 months ago

In terms of an ETA, I imagine I'll be releasing the next-gen version of Injection as soon as I know it works with Xcode 16.

paul-brenner commented 4 months ago

Was just looking around and noticed that InjectionNext exists. Looks pretty cool! But I wasn't really sure of it's status. Is it ready for fools like me to give it a try and open issues when I inevitably do something wrong? Or is it not quite there yet? If so, is it XCode 16 only?

johnno1962 commented 4 months ago

Hi Paul, InjectionNext is coming along nicely if you want to give it a try. I'm not pushing it just yet as I'm still getting useful feedback for some initial users.

Perjan commented 1 week ago

Using Xcode 16.1 this issue still persists. I spent 3 hours cleaning derived data and trying everything...

I tried the new InjectionNext, but that doesn't work with the Inject package.

Please let me know how if there is a fix @johnno1962

Thanks, Perjan

paul-brenner commented 1 week ago

I've been happy with InjectionNext for a few months now. I'm sure @johnno1962 will jump in with a more helpful answer, but if you think you are able to switch over, maybe open an issue on InjectionNext with what isn't working for you specifically? I assume you switched over to the InjectionNext package in you app when trying the InjectionNext?

Perjan commented 1 week ago

I've been happy with InjectionNext for a few months now. I'm sure @johnno1962 will jump in with a more helpful answer, but if you think you are able to switch over, maybe open an issue on InjectionNext with what isn't working for you specifically? I assume you switched over to the InjectionNext package in you app when trying the InjectionNext?

I tried to use injectionNext in combination with Inject, but apparently Inject is trying to find the app bundle InjectionIII, which was not present on my Mac. And the InjectionNext icon stays yellow, thus not reloading the changes...

paul-brenner commented 1 week ago

Ah, I've only been using InjectionNext with HotSwiftUI so maybe I'm unhelpful

johnno1962 commented 1 week ago

InjectionNext should be equivalent to InjectionIII from an Inject(HotSwiftUI) point of view. What isn't working? What version of InjectionIII were you using? Versions 5.0.1+ have a fix for this. Do you have a /Applications/Xcode.app?

Perjan commented 1 week ago

InjectionNext should be equivalent to InjectionIII from an Inject(HotSwiftUI) point of view. What isn't working? What version of InjectionIII were you using? Versions 5.0.1+ have a fix for this. Do you have a /Applications/Xcode.app?

Well there is not hot reloading and the InjectionNext icon remains yellow. And In the Xcode console I see that the Inject framework tries to find the InjectionIII bundle, but it doesn't. Xcode 16.1 is installed on my device.

johnno1962 commented 1 week ago

I'm sure you could have written that first response without the word "well". Is this on a real device (which is considerably more difficult and for which there may not currently be a solution if your problem is the Swift concurrency library)? If the icon never gets to orange at some point you are not connecting. Have you been able to get things running in the simulator? If you have added the InjectionNext Swift package to the same target as Inject it should not be trying to load any bundles.

Perjan commented 1 week ago

I'm sure you could have written that first response without the word "well". Is this on a real device (which is considerably more difficult and for which there may not currently be a solution if your problem is the Swift concurrency library)? If the icon never gets to orange at some point you are not connecting. Have you been able to get things running in the simulator? If you have added the InjectionNext Swift package to the same target as Inject it should not be trying to load any bundles.

Sorry about the "well", I didn't mean to offend you. I am running on the simulator. I am installing injectionNext on my other Mac now and I will let you know.

johnno1962 commented 1 week ago

What precisely is the problem we're chasing at the moment? Try to reach the point where InjectionNext connects as it will be easier to iterate over. If you still get Library not loaded: @rpath/libswift_Concurrency.dylib when you try to inject make sure you have a valid /Applications/Xcode.app. Otherwise, we can zoom it if you have the time.

Perjan commented 1 week ago

What precisely is the problem we're chasing at the moment? Try to reach the point where InjectionNext connects as it will be easier to iterate over. If you still get Library not loaded: @rpath/libswift_Concurrency.dylib when you try to inject make sure you have a valid /Applications/Xcode.app. Otherwise, we can zoom it if you have the time.

I finally moved to InjectionNext. Thanks for this amazing framework @johnno1962. I love it how fast it is and the console logs are more descriptive allowing me to find what to change.

Unfortunately now it doesn't allow me to build on a real device. I added a new issues on the InjectionNext repo. https://github.com/johnno1962/InjectionNext/issues/27

We can zoom any time.