johnno1962 / HotReloading

Hot reloading as a Swift Package

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

🔥 Loading .dylib has failed, This is likely because Swift code being injected refers to a function with a default argument. Rebuilding and re-running your project can resolve this.

Tate-zwt opened this issue · comments

Excuse me, can I only re-run if I encounter this problem?

🔥 Loading .dylib ...
🔥 Loading .dylib has failed, This is likely because Swift code being injected refers to a function with a default argument. Rebuilding and re-running your project can resolve this.
🔥 *** dlopen() error: dlopen(/Users/tate/Library/Developer/CoreSimulator/Devices/6BB1496B-CE17-4A53-A2E9-7A16CE440C6D/data/Containers/Data/Application/18B0CA15-7294-48C2-91E0-9A69C91FED5E/tmp/eval101.dylib, 2): Symbol not found: $s4Time10UNoticeBarC4show8duration9completedySd_ySbcSgtFfA0
Referenced from: /Users/tate/Library/Developer/CoreSimulator/Devices/6BB1496B-CE17-4A53-A2E9-7A16CE440C6D/data/Containers/Data/Application/18B0CA15-7294-48C2-91E0-9A69C91FED5E/tmp/eval101.dylib
Expected in: flat namespace
in /Users/tate/Library/Developer/CoreSimulator/Devices/6BB1496B-CE17-4A53-A2E9-7A16CE440C6D/data/Containers/Data/Application/18B0CA15-7294-48C2-91E0-9A69C91FED5E/tmp/eval101.dylib ***

Hi, these symbols should be defined but only after the second build after a clean build. Did it work after your rebuilt?

Hello,thank you for your response, restarting has no effect. The main reason is that commenting the following lines of code does not work. I don't really understand what is wrong with the code here?
// containerView.addSubview(startBtn)
// startBtn.snp.makeConstraints { (make) in
// make.centerX.equalToSuperview()
// make.bottom.equalTo(-28)
// make.height.equalTo(50)
// make.width.equalToSuperview().multipliedBy(0.75)
// }

Reported error:
🔥 Loading .dylib ...
🔥 Loading .dylib has failed, This is likely because Swift code being injected refers to a function with a default argument. Rebuilding and re-running your project can resolve this.
🔥 *** dlopen() error: dlopen(/Users/tate/Library/Developer/CoreSimulator/Devices/D69A82CD-CD24-4923-8CE2-CB48EC989754/data/Containers/Data/Application/FAB2FE49-E7EA-4B96-928E-C7B7DFD6661A/tmp/eval101.dylib, 2): Symbol not found: $s4Time10UNoticeBarC4show8duration9completedySd_ySbcSgtFfA0
Referenced from: /Users/tate/Library/Developer/CoreSimulator/Devices/D69A82CD-CD24-4923-8CE2-CB48EC989754/data/Containers/Data/Application/FAB2FE49-E7EA-4B96-928E-C7B7DFD6661A/tmp/eval101.dylib
Expected in: flat namespace
in /Users/tate/Library/Developer/CoreSimulator/Devices/D69A82CD-CD24-4923-8CE2-CB48EC989754/data/Containers/Data/Application/FAB2FE49-E7EA-4B96-928E-C7B7DFD6661A/tmp/eval101.dylib ***

I just found out that an error was reported when running on a real machine. The error log:
dyld: Library not loaded: @rpath/SwiftTrace.framework/SwiftTrace
Referenced from: /private/var/containers/Bundle/Application/C7F794AA-6352-4931-92CA-B48D2C4E1CF8/Time.app/Frameworks/HotReloading.framework/HotReloading
Reason: image not found
dyld: launch, loading dependent libraries
DYLD_LIBRARY_PATH=/usr/lib/system/introspection
DYLD_INSERT_LIBRARIES=/Developer/usr/lib/libBacktraceRecording.dylib:/Developer/usr/lib/libMainThreadChecker.dylib:/Developer/Library/PrivateFrameworks/DTDDISupport.framework/libViewDebuggerSupport.dylib
Message from debugger: Terminated due to signal 6

Hi, sorry this is holding you up. The problem you reported is strange one as the symbol should have a "_" at the end if it is for a default argument.

$ swift demangle
$s4Time10UNoticeBarC4show8duration9completedySd_ySbcSgtFfA0_
default argument 1 of Time.UNoticeBar.show(duration: Swift.Double, completed: (Swift.Bool) -> ()?) -> ()

I have to believe what you pasted is correct so I've made a small change to the HotReloading package to "unhide" symbols like the one you have seen available on branch "default-argument". Can you give it a try please?

On the second problem about SwiftTrace, how do you mean "Real Machine"? Do you mean an actual phone? I've never tried running HotReloading on a real device but I don't think it will work. Have you tried embedding the SwiftTrace library on the target's info tab?

Hi, sorry this is holding you up. The problem you reported is strange one as the symbol should have a "_" at the end if it is for a default argument.

$ swift demangle
$s4Time10UNoticeBarC4show8duration9completedySd_ySbcSgtFfA0_
default argument 1 of Time.UNoticeBar.show(duration: Swift.Double, completed: (Swift.Bool) -> ()?) -> ()

I have to believe what you pasted is correct so I've made a small change to the HotReloading package to "unhide" symbols like the one you have seen available on branch "default-argument". Can you give it a try please?

Hello, I updated the code of 1.4.3, but still encountered a new problem, modified the previous code, and then saved and reported a new error as shown in the figure:
image

Not sure what's happing there, it shouldn't be breaking on throw which is because of the undefined symbol. Did you try re-running or using the "default-argument" branch?

Hi~ o( ̄▽ ̄)ブ,I probably know why. As long as the Swift code file I wrote refers to the function with default parameters, there will be no hot update. I can compile the code by commenting it, but this will reduce the efficiency. I hope you can support this. To fix the problem, many of my functions have default parameter values, thank you!
public init(title: String? = nil, image: UIImage? = nil, textColor: UIColor = UIColor.white, backgroundColor: UIColor = UIColor.orange, barStyle: UNoticeBarStyle = .onNavigationBar, animationType: UNoticeBarAnimationType = .top) { self.title = title self.image = image self.textColor = textColor self.backgroundColor = backgroundColor self.barStyle = barStyle self.animationType = animationType }

If the code you're injecting refers to a function that has default arguments this is where you get the problem. One solution is to prove the default argument in this code but you shouldn't be being this as the "Unhide" code has a work-around which is included in HotReloading.

Sorry, does the question of'Unhide' mean this? I have already set it up, or am I doing something wrong?image

You're not doing anything wrong. That's the setup for HotReloading which includes my internal "Unhide" function so injecting default arguments should work (after the second build).

Thank you!

You're not doing anything wrong. That's the setup for HotReloading which includes my internal "Unhide" function so injecting default arguments should work (after the second build).

I meet the same problem after I build more than one time.
🔥 Loading .dylib ...
🔥 Loading .dylib has failed, This is likely because Swift code being injected refers to a function with a default argument. Rebuilding and re-running your project can resolve this.
🔥 ⚠️ dlopen() error: dlopen(/Users/xxx/Library/Developer/CoreSimulator/Devices/ACA0C019-A7F1-42DF-B31D-A4AFD1EE31F3/data/Containers/Data/Application/FFE45CEA-828B-48BB-9A74-9B37093BB8BA/tmp/eval101.dylib, 2): Symbol not found: _$s8ByteView6RouterC6sharedACvau
Referenced from: /Users/xxx/Library/Developer/CoreSimulator/Devices/ACA0C019-A7F1-42DF-B31D-A4AFD1EE31F3/data/Containers/Data/Application/FFE45CEA-828B-48BB-9A74-9B37093BB8BA/tmp/eval101.dylib
Expected in: flat namespace
in /Users/xxx/Library/Developer/CoreSimulator/Devices/ACA0C019-A7F1-42DF-B31D-A4AFD1EE31F3/data/Containers/Data/Application/FFE45CEA-828B-48BB-9A74-9B37093BB8BA/tmp/eval101.dylib

How to fix it? It's encountered a new problem when I remove default argument func. The console log as follow:
🔥 Compiling /Users/xxx/Workspace/xxxr/ToolBarPhoneViewController+Test.swift
🔥 Loading .dylib ...
🔥 Loaded .dylib - Ignore any duplicate class warning ^

Not a problem I've seen before. What version of Xcode is this?

Johns-Mac-mini HotReloading % swift demangle
_$s8ByteView6RouterC6sharedACvau
ByteView.Router.shared.unsafeMutableAddressor : ByteView.Router

Can you type the following command on your executable:
nm /<path_to_executable> | grep '$s8ByteView6RouterC6sharedACvau'
and tell me what it says?

@johnno1962
Thanks for reply.
My Xcode is Version 12.3 (12C33).
The grep of '$s8ByteView6RouterC6sharedACvau' as follow:
0000000105eb8ec0 t _$s8ByteView6RouterC6sharedACvau

I've never encountered this before but have put in what may be a fix. Can you update HotReloading but from the branch "unhiding-eval" in the Swift Packages inspector. You may have to run a send time.

@johnno1962
I use the branch "unhiding-eval", but it has a compile error as follow:
image

Sorry I'll delete that branch. You can use the 1.6.2 tagged release now.

@johnno1962
I try the version of 1.6.2, but encountered the same problem as follow:
🔥 Loading .dylib has failed, This is likely because Swift code being injected refers to a function with a default argument. Rebuilding and re-running your project (without a build clean) can resolve this.
🔥 ⚠️ dlopen() error: dlopen(/Users/xxx/Library/Developer/CoreSimulator/Devices/ACA0C019-A7F1-42DF-B31D-A4AFD1EE31F3/data/Containers/Data/Application/E4A3C57B-499A-4E61-8CAC-335A7BD43DAF/tmp/eval101.dylib, 2): Symbol not found: _$s8ByteView6RouterC6sharedACvau
Referenced from: /Users/xxx/Library/Developer/CoreSimulator/Devices/ACA0C019-A7F1-42DF-B31D-A4AFD1EE31F3/data/Containers/Data/Application/E4A3C57B-499A-4E61-8CAC-335A7BD43DAF/tmp/eval101.dylib
Expected in: flat namespace
in /Users/xxx/Library/Developer/CoreSimulator/Devices/ACA0C019-A7F1-42DF-B31D-A4AFD1EE31F3/data/Containers/Data/Application/E4A3C57B-499A-4E61-8CAC-335A7BD43DAF/tmp/eval101.dylib

Did you rebuild and re-run (without doing a build clean) and try again? This is necessary to have the patched object files make it into the app.

@johnno1962
It works! 🎇 But use "@objc func injected()" have an error, It's an infinite cycle in "func sweep(_ value: Any)", and use notification is working.
The error as follow:
🔥 Loaded .dylib - Ignore any duplicate class warning ^
🔥 ⚠️ Adding or removing methods on Swift classes is not supported. Your application will likely crash. ⚠️
🔥 Injected class 'xxx.ToolBarPhoneViewController'
🔥 As class ToolBarPhoneViewController has an @objc injected() method, HotReloading will perform a "sweep" of live instances to determine which objects to message. If this fails, subscribe to the notification "INJECTION_BUNDLE_NOTIFICATION" instead.

Great! Strange about the cycle through. You can set environment variable "DEBUG_SWEEP" in your scheme's launch settings to track down what is happening. I've never had an issue of an infinite loop.