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

Not working in Xcode 16 #520

Open
schwjustin opened this issue Sep 26, 2024 · 36 comments
Open

Not working in Xcode 16 #520

schwjustin opened this issue Sep 26, 2024 · 36 comments

Comments

@schwjustin
Copy link

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.

@johnno1962
Copy link
Owner

johnno1962 commented Sep 26, 2024

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

@nwywn
Copy link

nwywn commented Sep 27, 2024

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

@schwjustin
Copy link
Author

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

@schwjustin
Copy link
Author

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.

@johnno1962
Copy link
Owner

johnno1962 commented Sep 28, 2024

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.

@schwjustin
Copy link
Author

schwjustin commented Oct 16, 2024

@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
Copy link
Author

Any ideas how to get this working?

@johnno1962
Copy link
Owner

johnno1962 commented Oct 17, 2024

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?

@chadparker
Copy link

chadparker commented Oct 28, 2024

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

@johnno1962
Copy link
Owner

johnno1962 commented Oct 28, 2024

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 johnno1962 reopened this Oct 28, 2024
@chadparker
Copy link

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
Copy link

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
Copy link

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

@johnno1962
Copy link
Owner

johnno1962 commented Oct 28, 2024

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
Copy link
Owner

@johnno1962
Copy link
Owner

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

@chadparker
Copy link

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

@johnno1962
Copy link
Owner

johnno1962 commented Oct 29, 2024

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
Copy link
Owner

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

@chadparker
Copy link

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.

@johnno1962
Copy link
Owner

johnno1962 commented Nov 16, 2024

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 johnno1962 reopened this Nov 16, 2024
@chadparker
Copy link

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.

@johnno1962
Copy link
Owner

johnno1962 commented Nov 18, 2024

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.

@chadparker
Copy link

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

@johnno1962
Copy link
Owner

Any luck with your project now?

@chadparker
Copy link

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.

@johnno1962
Copy link
Owner

Have you tried Xcode 16.2?

@kaiserabliz
Copy link

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
Copy link

Screenshot 2024-12-12 at 5 43 15 PM

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

@johnno1962
Copy link
Owner

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

@kaiserabliz
Copy link

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

Thanks, I didn't realize this. First time using Inject.

@chadparker
Copy link

Have you tried Xcode 16.2?

Still crashes the same on 16.2, unfortunately.

@stephencelis
Copy link

@chadparker The DefaultInitializable symbol from XCTest Dynamic Overlay is pretty old and had to be removed for Swift 6 as code surrounding it caused compiler crashes. Could you update to the latest version to see if that helps? Note that you should still use the old package URL since SPM does not support renames as well as we thought:

https://github.com/pointfreeco/xctest-dynamic-overlay

We plan on finalizing the migration to the new library in the future.

@stephencelis
Copy link

@chadparker Just wanted to check in again about this.

@chadparker
Copy link

I have tried again:

  • switch all import XCTestDynamicOverlay to import IssueReporting (and XCTFail("") to reportIssue(""))

  • update to newest version:

        .package(
            url: "https://github.com/pointfreeco/xctest-dynamic-overlay",
            .upToNextMajor(from: Version(1, 4, 3))
        )
  • change my targets from this:
            dependencies: [
                ...
                .product(name: "XCTestDynamicOverlay", package: "xctest-dynamic-overlay")
            ]
  • to this:
            dependencies: [
                ...
                .product(name: "IssueReporting", package: "xctest-dynamic-overlay")
            ]

and I am still getting the crash.

It feels like XCTestDynamicOverlay/IssueReporting isn't the issue, but I can't say for sure.

@johnno1962
Copy link
Owner

There has to be a solution to this. Interested in another zoom session sometime?

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

6 participants