Not working in Xcode 16
I have a SwiftUI project and injection works as expected in xcode 15.2 with the app running in a simulator. However, in xcode 16 I get the 💉 Injected type # logs but the app doesn't actually update.
I tried deleting derived data, clean build folder, rebuild, double checked I have -Xlinker and -interposable, and double checked I'm running the debug scheme.
What version of the app are you using? Github Releases 5.0.1 and above include the change required for Xcode 16. https://github.com/johnno1962/InjectionIII/releases
I had the App Store version which was last updated 11mo ago. I installed latest version from Github and it's working now.
I had the app store version and tried the latest from github and it still doesn't work
Actually it's working on some views but on others that have @ObserveInjection var forceRedraw and .enableInjection() the app crashes. For example, I just tried to change the string in a Text("") and it crashed. In other views I'm able to make this change and it will live reload.
You're saying things that were previously reliable with 15.2 now occasionally work and sometimes crash with Xcode 16. That seems unlikely. Are you sure that you've added .enableInjection() at every level of views you are trying to inject? You can't just add it at the top level. If you're obeying all the rules outlined in the https://github.com/johnno1962/HotSwiftUI project and you're still seeing problems I'd be interested to investigate further. Previously, this has been very reliable.
@johnno1962
So the problem is a UIKit component in my SwiftUI project. I've had:
#if DEBUG extension UIViewController { @objc func injected() { viewDidLoad() } } #endif
in my project but even I comment out this code the same problem occurs. When I make a change even outside of the UIKIt component, the app crashes with error Thread 1: signal SIGABRT at this line in the my UIKIt component's viewDidLoad function:
view.updateConstraintsIfNeeded()
Any ideas how to get this working?
Have you tried Xcode 16.0? Is this specific to a particular version of iOS? Is there the possibility of have a look on Zoom? Can you try your app with the newer similar version of injection, https://github.com/johnno1962/InjectionNext?
When I use Xcode 16 I'm getting a signal SIGABRT on app launch in the simulator on my large iOS project when attempting to use InjectionIII and Inject. They work fine on Xcode 15.
I just now tried the InjectionNext and HotSwiftUI combo but I get the same crash on app launch when using Xcode 16.
Any diagnostics data I should gather to help figure this out?
We need to know what caused the SIGABRT as that could be many things. Are you able to post the stack trace here or email it to me at GitHub at johnholdsworth.com? Was there no explanatory text? Which iOS runtime is this?
This is what I get in Xcode. Is there a way to get more information?
Text of it, just in case:
dyld`__abort_with_payload:
0x10261e4c0 <+0>: mov x16, #0x209 ; =521
0x10261e4c4 <+4>: svc #0x80
-> 0x10261e4c8 <+8>: b.lo 0x10261e4e8 ; <+40>
0x10261e4cc <+12>: pacibsp
0x10261e4d0 <+16>: stp x29, x30, [sp, #-0x10]!
0x10261e4d4 <+20>: mov x29, sp
0x10261e4d8 <+24>: bl 0x1025b2e88 ; cerror_nocancel
0x10261e4dc <+28>: mov sp, x29
0x10261e4e0 <+32>: ldp x29, x30, [sp], #0x10
0x10261e4e4 <+36>: retab
0x10261e4e8 <+40>: ret
Called from here:
Text:
0x1025b5e98 <+1776>: strb wzr, [sp, #0x70]
0x1025b5e9c <+1780>: add x1, sp, #0xd0
0x1025b5ea0 <+1784>: add x2, sp, #0x50
0x1025b5ea4 <+1788>: mov x0, x21
0x1025b5ea8 <+1792>: bl 0x1025f3e78 ; dyld4::ExternallyViewableState::addImageInfo(lsl::Allocator&, dyld4::ExternallyViewableState::ImageInfo const&)
0x1025b5eac <+1796>: mov w8, #0x1 ; =1
0x1025b5eb0 <+1800>: str w8, [x19, #0x35c]
0x1025b5eb4 <+1804>: mov x0, x21
0x1025b5eb8 <+1808>: mov w1, #0x1 ; =1
0x1025b5ebc <+1812>: bl 0x1025f4660 ; dyld4::ExternallyViewableState::setInitialImageCount(unsigned int)
0x1025b5ec0 <+1816>: ldr x8, [x19, #0x8]
0x1025b5ec4 <+1820>: ldr w0, [x8, #0x44]
0x1025b5ec8 <+1824>: mov x1, #0x0 ; =0
0x1025b5ecc <+1828>: bl 0x102601e5c ; dyld3::MachOFile::isSimulatorPlatform(dyld3::Platform, dyld3::Platform*)
0x1025b5ed0 <+1832>: tbnz w0, #0x0, 0x1025b5ee4 ; <+1852>
0x1025b5ed4 <+1836>: ldr x1, [x19, #0x10]
0x1025b5ed8 <+1840>: add x2, sp, #0xd0
0x1025b5edc <+1844>: mov x0, x21
0x1025b5ee0 <+1848>: bl 0x1025f4ad8 ; dyld4::ExternallyViewableState::commit(lsl::Allocator&, lsl::Allocator&)
0x1025b5ee4 <+1852>: adrp x1, -5
0x1025b5ee8 <+1856>: add x1, x1, #0x0
0x1025b5eec <+1860>: mov x0, x19
0x1025b5ef0 <+1864>: bl 0x1025b63bc ; dyld4::prepare(dyld4::APIs&, dyld3::MachOAnalyzer const*)
-> 0x1025b5ef4 <+1868>: mov x20, x0
0x1025b5ef8 <+1872>: add x0, sp, #0xd0
0x1025b5efc <+1876>: bl 0x1025dd030 ; lsl::EphemeralAllocator::~EphemeralAllocator()
0x1025b5f00 <+1880>: ldr x16, [sp, #0x48]
0x1025b5f04 <+1884>: cbnz x16, 0x1025b5fd0 ; <+2088>
0x1025b5f08 <+1888>: mov x21, #0x0 ; =0
0x1025b5f0c <+1892>: b 0x1025b5ff8 ; <+2128>
0x1025b5f10 <+1896>: mov x9, #0xfffff0000 ; =68719411200
0x1025b5f14 <+1900>: movk x9, #0xc10c
0x1025b5f18 <+1904>: ldrb w8, [x9]
0x1025b5f1c <+1908>: cbz w8, 0x1025b6268 ; <+2752>
0x1025b5f20 <+1912>: ldrb w8, [x9]
0x1025b5f24 <+1916>: and w8, w8, #0xfe
0x1025b5f28 <+1920>: cmp w8, #0x2
0x1025b5f2c <+1924>: b.ne 0x1025b6268 ; <+2752>
0x1025b5f30 <+1928>: ldrb w8, [x9]
0x1025b5f34 <+1932>: and w8, w8, #0xfe
0x1025b5f38 <+1936>: cmp w8, #0x2
0x1025b5f3c <+1940>: b.ne 0x1025b6268 ; <+2752>
0x1025b5f40 <+1944>: mov x16, x23
0x1025b5f44 <+1948>: mrs x8, S3_6_C15_C1_5
0x1025b5f48 <+1952>: lsr x10, x8, #36
0x1025b5f4c <+1956>: ubfx x8, x8, #36, #1
0x1025b5f50 <+1960>: mov x17, x8
0x1025b5f54 <+1964>: pacdb x17, x16
Seems to be a problem with dynamic loading. I have to ask are you sure you don't get the ABRT when InjectionNext/HotSwiftUI isn't configured? As another idea, it could be trying to load a bundle in HotSwiftUI which shouldn't happen when the InjectionClient class is present if you look at the single source file. Have you tried adding a breakpoint in loadInjectionOnce in that file to see if it gets that far? Are you sure you added HotSwiftUI and InjectionNext Swift packages to the same target? Have you done a clean build after switching to InjectionNext?
You could experiment with some of this profiling to try to isolate the failure: https://developer.apple.com/library/archive/documentation/DeveloperTools/Conceptual/DynamicLibraries/100-Articles/LoggingDynamicLoaderEvents.html
Another thing to try: have you tried removing the -Xlinker -interposable flag?
I won't have time to get to this until tomorrow. Thank you for the quick response!
Another dimension to explore.. The main difference with Xcode 16 is how it links apps related to maintaining only one build area for previews. You could try reverting this change (with a "No"):
https://forums.developer.apple.com/forums/thread/761439
@chadparker, as you're the second person who has reported this I'd like to have tried to track it down but if you don't get back to me there isn't much I can do.
Yes I'm sorry, I haven't had the time to devote to troubleshooting this yet.
I tried for a couple hours today and without adding -Xlinker and -interposable I get this:
When I add them in one target specifically I got this, and no view update.
When I add them in the Project (affecting all targets), like I did with Inject/InjectionIII with Xcode 15, I get the crash as mentioned above. Nothing huge for an update, but that's what I've done so far.
Thanks for getting back, it's interesting it seems to be related to the -interposabe flag. The next thing to try would be to turn the "Enable Debug Dylib Support" flag off which was the main difference with Xcode 16. With luck you can leave this flag disabled and re-instate the -interposable flag and have injection work (though Xcode previews might be a little slower)
Trying the "Enable Debug Dylib Support" flag this morning. It looks like that property was not explicitly set in our project, and Xcode resolves it to "No".
If I set it to "Yes" I get this diff in the project file:
While setting it to "Yes" I get a crash caught by the debugger that looks like this:
I don't know much about dynamic linking, but if there's somewhere I can look or a question I can ask the rest of the team I'd love to.
At least enabling debug dylib is giving us a much more informative error message. I'd reintroduce -Xlinker -interposable target by target of your app rather than at the project level being sure to exclude the xctest-dynamic-overlay package. If you are able to zoom I'm available if you email and we could agree a time and we could cover more ground more quickly.
I just sent you an email. A zoom call would be better, I agree!
Any luck with your project now?
I replaced all of the XCTFail calls that were not in test files with reportIssue, (and changing import XCTestDynamicOverlay to import IssueReporting), but I'm still getting the crash. This time even though I have this set: ENABLE_DEBUG_DYLIB = YES; the debugger doesn't catch a crash referring to XCTestDynamicOverlay so that's maybe a slight improvement, but unfortunately doesn't solve the problem.
I'm going to show this issue to one of our senior devs to see if he has any ideas.
Have you tried Xcode 16.2?
And after putting NO to ENABLE_DEBUG_DYLIB, I got a different error.
It's -Xlinker -interposable not -interposable -Xlinker. -Xlinker introduces an option that is sent through to the linker.