InjectionIII icon indicating copy to clipboard operation
InjectionIII copied to clipboard

Not working in Xcode 16

Open schwjustin opened this issue 1 year ago • 8 comments

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.

schwjustin avatar Sep 26 '24 19:09 schwjustin

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

johnno1962 avatar Sep 26 '24 19:09 johnno1962

I had the App Store version which was last updated 11mo ago. I installed latest version from Github and it's working now.

nwywn avatar Sep 27 '24 19:09 nwywn

I had the app store version and tried the latest from github and it still doesn't work

schwjustin avatar Sep 28 '24 05:09 schwjustin

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.

schwjustin avatar Sep 28 '24 05:09 schwjustin

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 avatar Sep 28 '24 16:09 johnno1962

@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()

schwjustin avatar Oct 16 '24 23:10 schwjustin

Any ideas how to get this working?

schwjustin avatar Oct 16 '24 23:10 schwjustin

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?

johnno1962 avatar Oct 17 '24 08:10 johnno1962

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?

Screenshot 2024-10-28 at 10 30 08 AM

chadparker avatar Oct 28 '24 17:10 chadparker

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?

johnno1962 avatar Oct 28 '24 17:10 johnno1962

This is what I get in Xcode. Is there a way to get more information?

Screenshot 2024-10-28 at 10 42 35 AM

chadparker avatar Oct 28 '24 17:10 chadparker

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    

chadparker avatar Oct 28 '24 17:10 chadparker

Called from here:

Screenshot 2024-10-28 at 10 54 58 AM

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

chadparker avatar Oct 28 '24 17:10 chadparker

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?

johnno1962 avatar Oct 28 '24 18:10 johnno1962

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

johnno1962 avatar Oct 28 '24 18:10 johnno1962

Another thing to try: have you tried removing the -Xlinker -interposable flag?

johnno1962 avatar Oct 28 '24 20:10 johnno1962

I won't have time to get to this until tomorrow. Thank you for the quick response!

chadparker avatar Oct 28 '24 20:10 chadparker

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"): image https://forums.developer.apple.com/forums/thread/761439

johnno1962 avatar Oct 29 '24 00:10 johnno1962

@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.

johnno1962 avatar Nov 07 '24 16:11 johnno1962

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:

Screenshot 2024-11-15 at 4 02 31 PM

When I add them in one target specifically I got this, and no view update.

Screenshot 2024-11-15 at 4 08 16 PM

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.

chadparker avatar Nov 16 '24 00:11 chadparker

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)

johnno1962 avatar Nov 16 '24 09:11 johnno1962

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".

Screenshot 2024-11-18 at 8 08 51 AM

If I set it to "Yes" I get this diff in the project file:

Screenshot 2024-11-18 at 8 10 56 AM

While setting it to "Yes" I get a crash caught by the debugger that looks like this:

Screenshot 2024-11-18 at 8 13 01 AM

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.

chadparker avatar Nov 18 '24 16:11 chadparker

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.

johnno1962 avatar Nov 18 '24 16:11 johnno1962

I just sent you an email. A zoom call would be better, I agree!

chadparker avatar Nov 18 '24 22:11 chadparker

Any luck with your project now?

johnno1962 avatar Nov 26 '24 10:11 johnno1962

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.

chadparker avatar Dec 09 '24 17:12 chadparker

Have you tried Xcode 16.2?

johnno1962 avatar Dec 10 '24 22:12 johnno1962

Screenshot 2024-12-12 at 5 32 48 PM I am getting these compiler errors on Xcode16.1, is there any way to fix this? Planning to give 16.2 a shot this evening.

kaiserabliz avatar Dec 12 '24 22:12 kaiserabliz

Screenshot 2024-12-12 at 5 43 15 PM

And after putting NO to ENABLE_DEBUG_DYLIB, I got a different error.

kaiserabliz avatar Dec 12 '24 22:12 kaiserabliz

It's -Xlinker -interposable not -interposable -Xlinker. -Xlinker introduces an option that is sent through to the linker.

johnno1962 avatar Dec 13 '24 01:12 johnno1962