Hot reloading failing on real iOS device
adrienbaron opened this issue Β· comments
Seems like I can't get hot reloading to work on my iOS device.
Setup:
- iPhone 14 Pro running iOS 16.5 (20F66)
- macOS 13.4.1 (22F82) (M1 Pro)
- XCode 14.3 (14E222b)
What I've done:
- Downloaded and installed InjectionIII (latest version: 4.7.0).
- Added this library to my new Swift project
- Added the linker flags
-
Ran
defaults write com.johnholdsworth.InjectionIII deviceUnlock any
-
Added an environment variable to my scheme with my computer local IP
- Added the
Run Script/Build Phase
I can see it being set when reading from the terminal:
β ~ defaults read com.johnholdsworth.InjectionIII
{
"/Users/adrien.baron/perso/volumizer-new/Volumizer/Volumizer.xcodeproj" = 55B1F64367A6DB4244C5D555C6062DAC71AF1B7F;
deviceInform = Informed;
deviceUnlock = any;
lastProject = "/Users/adrien.baron/perso/volumizer-new/Volumizer/Volumizer.xcodeproj";
lastWatched = "/Users/adrien.baron/perso/volumizer-new/Volumizer";
}
What I'm seeing:
App starts on the phone, and connect successfully to the InjectionIII
app:
π₯ HotReloading connected /Users/adrien.baron/perso/volumizer-new/Volumizer/Volumizer.xcodeproj
π₯ Watching files under the directory /Users/adrien.baron/perso/volumizer-new/Volumizer
π₯ Compiling /Users/adrien.baron/perso/volumizer-new/Volumizer/Volumizer/ContentView.swift
2023-06-25 11:14:07.631726+0100 Volumizer[7136:673478] π₯ ***** Tests bundle wasn't found - did you run the tests target before running the application?
It does warn about test bundles, but I don't have test for this app yet (so assuming this is unrelated).
What fails:
When I do some change to the code, the app rebuilds but complains about .dylib
having invalid code signing:
π₯ Loading .dylib ...
π₯ β οΈ dlopen() error: dlopen(/private/var/mobile/Containers/Data/Application/2688C0CC-2A9A-4173-A62D-F7A418E59BE7/tmp/eval101.dylib, 0x0002): tried: '/usr/lib/system/introspection/eval101.dylib' (no such file, not in dyld cache), '/private/var/mobile/Containers/Data/Application/2688C0CC-2A9A-4173-A62D-F7A418E59BE7/tmp/eval101.dylib' (code signature invalid in <A283E7DA-CBDA-3FC0-9668-CB1F5168D485> '/private/var/mobile/Containers/Data/Application/2688C0CC-2A9A-4173-A62D-F7A418E59BE7/tmp/eval101.dylib' (errno=1) sliceOffset=0x00000000, codeBlobOffset=0x0001B8B0, codeBlobSize=0x00004E30), '/private/preboot/Cryptexes/OS/private/var/mobile/Containers/Data/Application/2688C0CC-2A9A-4173-A62D-F7A418E59BE7/tmp/eval101.dylib' (no such file), '/private/var/mobile/Containers/Data/Application/2688C0CC-2A9A-4173-A62D-F7A418E59BE7/tmp/eval101.dylib' (code signature invalid in <A283E7DA-CBDA-3FC0-9668-CB1F5168D485> '/private/var/mobile/Containers/Data/Application/2688C0CC-2A9A-4173-A62D-F7A418E59BE7/tmp/eval101.dylib' (errno=1) sliceOffset=0x00000000, codeBlobOffset=0x0001B8B0, codeBlobSize=0x00004E30)
π₯ β οΈ Loading .dylib has failed due to invalid code signing.
π₯ Add the following as a Run Script/Build Phase:
defaults write com.johnholdsworth.InjectionIII "$PROJECT_FILE_PATH" "$EXPANDED_CODE_SIGN_IDENTITY"
Nothing I've tried so far seemed to have made any difference, but I also can't find anyone online having this issue, am I holding it wrong π ?
Note
I sadly can't use the simulator while working as I'm using RoomPlan and it doesn't run in a simulator
Hi, getting codesigning right is difficult and the code sign (errno=1) doesn't give you much to go on.
The first thing to check is that Injection is signing correctly. Can you run the Injection app from the command line
$ /Applications/InjectionIII.app/Contents/MacOS/InjectionIII
Then look for the line π InjectionIII Signing with identity: 511C1148E461780FD8B3C04906E..., check the identity is the same as for the app in the build logs and look for any error that might follow it.
@johnno1962 thank you for coming back to me that quickly! I've ran the app in a terminal and I'm getting a similar error there too. Nothing in those logs strike me as super suspicious, but I'm quite new to Swift dev π
2023-06-25 20:05:36.052 InjectionIII[28722:1161158] Connection from 192.168.1.242:59057
2023-06-25 20:05:36.052 InjectionIII[28722:1179193] π InjectionIII Connection for project file: /Users/adrien.baron/perso/volumizer-new/Volumizer/Volumizer.xcodeproj
2023-06-25 20:05:36.174 InjectionIII[28722:1179193] π InjectionIII Using tmp dir: /private/var/mobile/Containers/Data/Application/48BE6955-97CB-4072-8CBA-AB869A6BB5F2/tmp/
2023-06-25 20:05:44.950 InjectionIII[28722:1179276] π InjectionIII evalError: Compiling /Users/adrien.baron/perso/volumizer-new/Volumizer/Volumizer/ContentView.swift
2023-06-25 20:05:45.298 InjectionIII[28722:1179276] π InjectionIII Signing with identity: 55B1F64367A6DB4244C5D555C6062DAC71AF1B7F
2023-06-25 20:05:45.424 InjectionIII[28722:1179193] π InjectionIII Injection error: Error Domain=SwiftEval Code=-1 "dlopen() error: dlopen(/private/var/mobile/Containers/Data/Application/48BE6955-97CB-4072-8CBA-AB869A6BB5F2/tmp/eval101.dylib, 0x0002): tried: '/usr/lib/system/introspection/eval101.dylib' (no such file, not in dyld cache), '/private/var/mobile/Containers/Data/Application/48BE6955-97CB-4072-8CBA-AB869A6BB5F2/tmp/eval101.dylib' (code signature invalid in <8C1A4437-765F-3D39-8587-08FE4370F1AA> '/private/var/mobile/Containers/Data/Application/48BE6955-97CB-4072-8CBA-AB869A6BB5F2/tmp/eval101.dylib' (errno=1) sliceOffset=0x00000000, codeBlobOffset=0x0001B8B0, codeBlobSize=0x00004E30), '/private/preboot/Cryptexes/OS/private/var/mobile/Containers/Data/Application/48BE6955-97CB-4072-8CBA-AB869A6BB5F2/tmp/eval101.dylib' (no such file), '/private/var/mobile/Containers/Data/Application/48BE6955-97CB-4072-8CBA-AB869A6BB5F2/tmp/eval101.dylib' (code signature invalid in <8C1A4437-765F-3D39-8587-08FE4370F1AA> '/private/var/mobile/Containers/Data/Application/48BE6955-97CB-4072-8CBA-AB869A6BB5F2/tmp/eval101.dylib' (errno=1) sliceOffset=0x00000000, codeBlobOffset=0x0001B8B0, codeBlobSize=0x00004E30)
π₯ β οΈ Loading .dylib has failed due to invalid code signing.
π₯ Add the following as a Run Script/Build Phase:
defaults write com.johnholdsworth.InjectionIII "$PROJECT_FILE_PATH" "$EXPANDED_CODE_SIGN_IDENTITY"" UserInfo={NSLocalizedDescription=dlopen() error: dlopen(/private/var/mobile/Containers/Data/Application/48BE6955-97CB-4072-8CBA-AB869A6BB5F2/tmp/eval101.dylib, 0x0002): tried: '/usr/lib/system/introspection/eval101.dylib' (no such file, not in dyld cache), '/private/var/mobile/Containers/Data/Application/48BE6955-97CB-4072-8CBA-AB869A6BB5F2/tmp/eval101.dylib' (code signature invalid in <8C1A4437-765F-3D39-8587-08FE4370F1AA> '/private/var/mobile/Containers/Data/Application/48BE6955-97CB-4072-8CBA-AB869A6BB5F2/tmp/eval101.dylib' (errno=1) sliceOffset=0x00000000, codeBlobOffset=0x0001B8B0, codeBlobSize=0x00004E30), '/private/preboot/Cryptexes/OS/private/var/mobile/Containers/Data/Application/48BE6955-97CB-4072-8CBA-AB869A6BB5F2/tmp/eval101.dylib' (no such file), '/private/var/mobile/Containers/Data/Application/48BE6955-97CB-4072-8CBA-AB869A6BB5F2/tmp/eval101.dylib' (code signature invalid in <8C1A4437-765F-3D39-8587-08FE4370F1AA> '/private/var/mobile/Containers/Data/Application/48BE6955-97CB-4072-8CBA-AB869A6BB5F2/tmp/eval101.dylib' (errno=1) sliceOffset=0x00000000, codeBlobOffset=0x0001B8B0, codeBlobSize=0x00004E30)
π₯ β οΈ Loading .dylib has failed due to invalid code signing.
π₯ Add the following as a Run Script/Build Phase:
defaults write com.johnholdsworth.InjectionIII "$PROJECT_FILE_PATH" "$EXPANDED_CODE_SIGN_IDENTITY"}
2023-06-25 20:05:45.577 InjectionIII[28722:1178734] π InjectionIII evalError: Compiling /Users/adrien.baron/perso/volumizer-new/Volumizer/Volumizer/ContentView.swift
2023-06-25 20:05:45.904 InjectionIII[28722:1178734] π InjectionIII Signing with identity: 55B1F64367A6DB4244C5D555C6062DAC71AF1B7F
2023-06-25 20:05:46.079 InjectionIII[28722:1179193] π InjectionIII Injection error: Error Domain=SwiftEval Code=-1 "dlopen() error: dlopen(/private/var/mobile/Containers/Data/Application/48BE6955-97CB-4072-8CBA-AB869A6BB5F2/tmp/eval102.dylib, 0x0002): tried: '/usr/lib/system/introspection/eval102.dylib' (no such file, not in dyld cache), '/private/var/mobile/Containers/Data/Application/48BE6955-97CB-4072-8CBA-AB869A6BB5F2/tmp/eval102.dylib' (code signature invalid in <A435AA7A-D3DB-35DE-A046-79AAD1B26CBC> '/private/var/mobile/Containers/Data/Application/48BE6955-97CB-4072-8CBA-AB869A6BB5F2/tmp/eval102.dylib' (errno=1) sliceOffset=0x00000000, codeBlobOffset=0x0001B8B0, codeBlobSize=0x00004E30), '/private/preboot/Cryptexes/OS/private/var/mobile/Containers/Data/Application/48BE6955-97CB-4072-8CBA-AB869A6BB5F2/tmp/eval102.dylib' (no such file), '/private/var/mobile/Containers/Data/Application/48BE6955-97CB-4072-8CBA-AB869A6BB5F2/tmp/eval102.dylib' (code signature invalid in <A435AA7A-D3DB-35DE-A046-79AAD1B26CBC> '/private/var/mobile/Containers/Data/Application/48BE6955-97CB-4072-8CBA-AB869A6BB5F2/tmp/eval102.dylib' (errno=1) sliceOffset=0x00000000, codeBlobOffset=0x0001B8B0, codeBlobSize=0x00004E30)
π₯ β οΈ Loading .dylib has failed due to invalid code signing.
π₯ Add the following as a Run Script/Build Phase:
defaults write com.johnholdsworth.InjectionIII "$PROJECT_FILE_PATH" "$EXPANDED_CODE_SIGN_IDENTITY"" UserInfo={NSLocalizedDescription=dlopen() error: dlopen(/private/var/mobile/Containers/Data/Application/48BE6955-97CB-4072-8CBA-AB869A6BB5F2/tmp/eval102.dylib, 0x0002): tried: '/usr/lib/system/introspection/eval102.dylib' (no such file, not in dyld cache), '/private/var/mobile/Containers/Data/Application/48BE6955-97CB-4072-8CBA-AB869A6BB5F2/tmp/eval102.dylib' (code signature invalid in <A435AA7A-D3DB-35DE-A046-79AAD1B26CBC> '/private/var/mobile/Containers/Data/Application/48BE6955-97CB-4072-8CBA-AB869A6BB5F2/tmp/eval102.dylib' (errno=1) sliceOffset=0x00000000, codeBlobOffset=0x0001B8B0, codeBlobSize=0x00004E30), '/private/preboot/Cryptexes/OS/private/var/mobile/Containers/Data/Application/48BE6955-97CB-4072-8CBA-AB869A6BB5F2/tmp/eval102.dylib' (no such file), '/private/var/mobile/Containers/Data/Application/48BE6955-97CB-4072-8CBA-AB869A6BB5F2/tmp/eval102.dylib' (code signature invalid in <A435AA7A-D3DB-35DE-A046-79AAD1B26CBC> '/private/var/mobile/Containers/Data/Application/48BE6955-97CB-4072-8CBA-AB869A6BB5F2/tmp/eval102.dylib' (errno=1) sliceOffset=0x00000000, codeBlobOffset=0x0001B8B0, codeBlobSize=0x00004E30)
π₯ β οΈ Loading .dylib has failed due to invalid code signing.
π₯ Add the following as a Run Script/Build Phase:
defaults write com.johnholdsworth.InjectionIII "$PROJECT_FILE_PATH" "$EXPANDED_CODE_SIGN_IDENTITY"}
It seems to sign with identity: 55B1F64367A6DB4244C5D555C6062DAC71AF1B7F
I've checked the build log and the signature do seem to match:
export EXPANDED_CODE_SIGN_IDENTITY\=55B1F64367A6DB4244C5D555C6062DAC71AF1B7F
...
cd /Users/adrien.baron/perso/volumizer-new/Volumizer
Signing Identity: "Apple Development: axx@gmail.com (LBMXXXX)"
Provisioning Profile: "iOS Team Provisioning Profile: net.abaron.volumizerapp"
(876dd9d8-XXX)
/usr/bin/codesign --force --sign 55B1F64367A6DB4244C5D555C6062DAC71AF1B7F --timestamp\=none --preserve-metadata\=identifier,entitlements,flags --generate-entitlement-der /Users/adrien.baron/Library/Developer/Xcode/DerivedData/Volumizer-emiufhnxurptayfpuzkoyaghlqne/Build/Products/Debug-iphoneos/Volumizer.app/Frameworks/SwiftTrace.framework
Feel free to ask if I can provide anything else π!
Thanks for the detailed reports. The next thing to try is to update the HotReloading package and replace the "Build Phase" you added with the following instead of running the InjectionIII.app:
if [ -d $SYMROOT/../../SourcePackages ]; then
$SYMROOT/../../SourcePackages/checkouts/HotReloading/start_daemon.sh
fi
This runs the app's code but as a daemon which is easier to work on. If this doesn't work I can TeamView to investigate further. Would that be possible?
@johnno1962 replaced the script with the code to start the daemon, and killed the InjectionIII app. Then started the app, it does start the daemon and connect, but still the same issue with dylib.
Happy to TeamView (or similar) if that can help! You can DM me on Twitter?
Very strange problem. Using the daemon eliminated a couple of things. Could you try switching HotReloading to branch "include-entitlements" which adds the entitlements file to the code signing arguments? HotReloading uses a cache and to make sure it gets flushed remove the file /tmp/iOS_builds.plist before you start your app. You should see the new -entitlements argument in the com.johnholdsworth.InjectionIII defaults after that.
@johnno1962 ok done this, still the same issue π :
- I do get the
entitlements
flag:
β ~ defaults read com.johnholdsworth.InjectionIII
{
"/Users/adrien.baron/perso/volumizer/Volumizer/Volumizer.xcodeproj" = "55B1F64367A6DB4244C5D555C6062DAC71AF1B7F --entitlements /Users/adrien.baron/Library/Developer/Xcode/DerivedData/Volumizer-csaltqlpifoltncgdifgioalxcwi/Build/Intermediates.noindex/Volumizer.build/Debug-iphoneos/Volumizer.build/Volumizer.app.xcent";
deviceInform = Informed;
deviceUnlock = any;
lastProject = "/Users/adrien.baron/perso/volumizer-new/Volumizer/Volumizer.xcodeproj";
lastWatched = "/Users/adrien.baron/perso/volumizer-new/Volumizer";
}
- I did delete the cache file, although it was called
/tmp/maciOS_builds.plist
Here are the logs/cache I've found in /tmp
(hot_reloading.log
, maciOS_builds.plist
and unhide_object.log
).
I've cleared them, started the app, did one change and then got them. Hope this helps πββοΈ!
Still looking at this, about the only progress I've made is to replicate the code signing error=1 if you add the following to the Build phase (which stops the --entitlements "fix" being bypassed by values in the environment):
unset EXPANDED_CODE_SIGN_IDENTITY
unset CODE_SIGN_IDENTITY
Give me a little longer, I've not seen this code signing problem before. Usually it is connecting over the network that is the problem.
@johnno1962 the code is also very new, so I'm also happy to give you access to that repo if that helps debugging π (sorry should have offered that before)
EDIT: Added you, the branch is feature/inject
π
Thanks, I'll take a look and get back to you.
Can't get your app not to work :S I've messaged you on twitter if you want to TeamView or email me at github at johnholdsworth.com.
Can't get your app not to work :S
Argh the dreaded "It works on my machine" π , will be in touch!
This turned out to be a change to the default value for the PATH environment variable. This should be fixed in the 4.7.4 release.