keiwando / nativefileso

Unity - Native file dialogs and file type associations on Windows, macOS, iOS and Android
Mozilla Public License 2.0
92 stars 11 forks source link

M1 Mac support #8

Open noname77 opened 2 years ago

noname77 commented 2 years ago

hi,

I've just started trying out your package on an M1 Mac with native unity editor. when running in the editor im getting DllNotFoundException exception

DllNotFoundException: NativeFileSOMac assembly:<unknown assembly> type:<unknown type> member:(null)

im fairly sure this is because the .bundle file was built for x86_64 only (seen the same issue with a different plugin)

macOS % lipo -archs NativeFileSOMac.bundle/Contents/MacOS/NativeFileSOMac
x86_64

whereas for a multi arch .bundle it should read:

macOS % lipo -archs AnotherPlugin.bundle/Contents/MacOS/AnotherPlugin 
x86_64 arm64

any chance you could rebuild the bundle as an universal binary for the next release?

here's some info: https://developer.apple.com/documentation/apple-silicon/building-a-universal-macos-binary

best, wiktor

keiwando commented 2 years ago

Thanks for letting me know! I unfortunately don't have any time to work on this at the moment, so if it's urgent, you can find the Xcode projects here and you could try to edit the build config there and re-build yourself until I get around to it.

fredzvt-drest commented 2 years ago

Any progress on this issue? @noname77

noname77 commented 2 years ago

hey @fredzvt-drest

I'm also very busy recently and since I use this plugin only for a minor feature in a side project its quite low priority.

I just switch to an Intel Unity build if I need to test in editor player on an M1 Mac, but since this part doesn't really change much I just build for Android / iOS (main use) with a regular apple silicon version when needed (iirc).

also, thanks for the pointer @keiwando! I might give it a go if I have more time next year, but more likely ill just wait patiently 🙄

keiwando commented 1 year ago

I just uploaded a new package which contains the macOS binary that was built for both Apple Silicon and Intel architectures. I also checked and the demo project runs both in the editor and as a build on an M1 Macbook Pro. Please let me know if it also works for you.

noname77 commented 1 year ago

thanks for the heads up!

I updated with the v1.0.4 .unitypackage and got

Prefab instance problem: NativeFileSOUnityEvent (Missing Prefab with guid: fe215ce588c244bf7a653d09a27acd28)

after re-adding the updated prefab to the scene this error is gone, but with Apple Silicon Unity Editor im still getting

DllNotFoundException: NativeFileSOMac assembly:<unknown assembly> type:<unknown type> member:(null)
Keiwando.NFSO.NativeFileSOMac.OpenFiles (Keiwando.NFSO.SupportedFileType[] fileTypes, System.Boolean canSelectMultiple, System.String title, System.String directory, System.Action`2[T1,T2] onCompletion) (at Assets/ThirdParty/NativeFileSO/Scripts/NativeFileSOMac.cs:99)
Keiwando.NFSO.NativeFileSOMac.OpenFile (Keiwando.NFSO.SupportedFileType[] supportedTypes, System.Action`2[T1,T2] onCompletion) (at Assets/ThirdParty/NativeFileSO/Scripts/NativeFileSOMac.cs:65)
Keiwando.NFSO.NativeFileSOMacWin.OpenFile (Keiwando.NFSO.SupportedFileType[] supportedTypes, System.Action`2[T1,T2] onCompletion) (at Assets/ThirdParty/NativeFileSO/Scripts/NativeFileSOMacWin.cs:123)
Keiwando.NFSO.NativeFileSO.OpenFile (Keiwando.NFSO.SupportedFileType[] supportedTypes, System.Action`2[T1,T2] onCompletion) (at Assets/ThirdParty/NativeFileSO/Scripts/NativeFileSO.cs:146)

when running the lipo program on the .bundle it still shows x86_64 arch only

% lipo -archs NativeFileSOMac.bundle/Contents/MacOS/NativeFileSOMac
x86_64

I also run the lipo command on the .bundle included in source .zip with the same results

As I mentioned in the original post, I think for the bundle to run successfully in Apple Silicon Editor the output should instead show

macOS % lipo -archs AnotherPlugin.bundle/Contents/MacOS/AnotherPlugin 
x86_64 arm64

Is this what you're getting?

Thanks again for looking into this! Wiktor

keiwando commented 1 year ago

Okay, this should actually be fixed now with the 1.0.5 version. lipo now outputs x86_64 arm64. The Xcode scheme was accidentally still set to Debug, which caused it to only build for the current architecture even though the build settings included Intel and Apple Silicon. No idea why it still ran without issues for me on an M1 Mac…

noname77 commented 1 year ago

thanks,

although it looks like the bundle is built for both platforms now

% lipo -archs NativeFileSOMac.bundle/Contents/MacOS/NativeFileSOMac
x86_64 arm64

I am now getting (from unity editor log at ~/Library/Logs/Unity/Editor.log)

Fallback handler could not load library /Applications/Unity/Hub/Editor/2021.3.13f1/Unity.app/Contents/Frameworks/MonoBleedingEdge/lib/NativeFileSOMac
Fallback handler could not load library /Applications/Unity/Hub/Editor/2021.3.13f1/Unity.app/Contents/Frameworks/MonoBleedingEdge/lib/libNativeFileSOMac.dylib
Fallback handler could not load library /Applications/Unity/Hub/Editor/2021.3.13f1/Unity.app/Contents/Frameworks/MonoBleedingEdge/lib/libNativeFileSOMac.dylib
Fallback handler could not load library /Applications/Unity/Hub/Editor/2021.3.13f1/Unity.app/Contents/Frameworks/MonoBleedingEdge/lib/libNativeFileSOMac.so
Fallback handler could not load library /Applications/Unity/Hub/Editor/2021.3.13f1/Unity.app/Contents/Frameworks/MonoBleedingEdge/lib/libNativeFileSOMac.bundle
Fallback handler could not load library /Applications/Unity/Hub/Editor/2021.3.13f1/Unity.app/Contents/Frameworks/MonoBleedingEdge/lib/NativeFileSOMac
Fallback handler could not load library /Applications/Unity/Hub/Editor/2021.3.13f1/Unity.app/Contents/Frameworks/MonoBleedingEdge/lib/libNativeFileSOMac
Fallback handler could not load library /Applications/Unity/Hub/Editor/2021.3.13f1/Unity.app/Contents/Frameworks/MonoBleedingEdge/lib/libNativeFileSOMac.dylib
Fallback handler could not load library /Applications/Unity/Hub/Editor/2021.3.13f1/Unity.app/Contents/Frameworks/MonoBleedingEdge/lib/libNativeFileSOMac.dylib
Fallback handler could not load library /Applications/Unity/Hub/Editor/2021.3.13f1/Unity.app/Contents/Frameworks/MonoBleedingEdge/lib/libNativeFileSOMac.so
Fallback handler could not load library /Applications/Unity/Hub/Editor/2021.3.13f1/Unity.app/Contents/Frameworks/MonoBleedingEdge/lib/libNativeFileSOMac.bundle
Fallback handler could not load library /Applications/Unity/Hub/Editor/2021.3.13f1/Unity.app/Contents/Frameworks/MonoBleedingEdge/lib/libNativeFileSOMac
Fallback handler could not load library /Applications/Unity/Hub/Editor/2021.3.13f1/Unity.app/Contents/Frameworks/MonoBleedingEdge/lib/NativeFileSOMac
Fallback handler could not load library /Applications/Unity/Hub/Editor/2021.3.13f1/Unity.app/Contents/Frameworks/MonoBleedingEdge/lib/libNativeFileSOMac.dylib
Fallback handler could not load library /Applications/Unity/Hub/Editor/2021.3.13f1/Unity.app/Contents/Frameworks/MonoBleedingEdge/lib/libNativeFileSOMac.dylib
Fallback handler could not load library /Applications/Unity/Hub/Editor/2021.3.13f1/Unity.app/Contents/Frameworks/MonoBleedingEdge/lib/libNativeFileSOMac.so
Fallback handler could not load library /Applications/Unity/Hub/Editor/2021.3.13f1/Unity.app/Contents/Frameworks/MonoBleedingEdge/lib/libNativeFileSOMac.bundle
Fallback handler could not load library /Applications/Unity/Hub/Editor/2021.3.13f1/Unity.app/Contents/Frameworks/MonoBleedingEdge/lib/NativeFileSOMac
Fallback handler could not load library /Applications/Unity/Hub/Editor/2021.3.13f1/Unity.app/Contents/Frameworks/MonoBleedingEdge/lib/libNativeFileSOMac
Fallback handler could not load library /Applications/Unity/Hub/Editor/2021.3.13f1/Unity.app/Contents/Frameworks/MonoBleedingEdge/lib/libNativeFileSOMac.dylib
Fallback handler could not load library /Applications/Unity/Hub/Editor/2021.3.13f1/Unity.app/Contents/Frameworks/MonoBleedingEdge/lib/libNativeFileSOMac.dylib
Fallback handler could not load library /Applications/Unity/Hub/Editor/2021.3.13f1/Unity.app/Contents/Frameworks/MonoBleedingEdge/lib/libNativeFileSOMac.so
Fallback handler could not load library /Applications/Unity/Hub/Editor/2021.3.13f1/Unity.app/Contents/Frameworks/MonoBleedingEdge/lib/libNativeFileSOMac.bundle
Fallback handler could not load library /Applications/Unity/Hub/Editor/2021.3.13f1/Unity.app/Contents/Frameworks/MonoBleedingEdge/lib/libNativeFileSOMac
DllNotFoundException: NativeFileSOMac assembly:<unknown assembly> type:<unknown type> member:(null)

if I run open NativeFileSOMac.bundle/Contents/MacOS/NativeFileSOMac from the terminal I get

% open NativeFileSOMac.bundle/Contents/MacOS/NativeFileSOMac 
The application cannot be opened for an unexpected reason, error=Error Domain=NSOSStatusErrorDomain Code=-128 "userCanceledErr" UserInfo={_LSLine=4101, _LSFunction=_LSOpenStuffCallLocal}
image

I then tried adding an executable permission and open again

% chmod +x NativeFileSOMac.bundle/Contents/MacOS/NativeFileSOMac
open NativeFileSOMac.bundle/Contents/MacOS/NativeFileSOMac  

this added the option in security & privacy settings

Screenshot 2023-02-14 at 15 50 53 image

running in unity afterwards I get

Start importing Assets/ThirdParty/NativeFileSO/Plugins/macOS/NativeFileSOMac.bundle using Guid(d85c44712b96b4fc7af0c963a31bdad4) Importer(-1,00000000000000000000000000000000)  -> (artifact id: 'fe84e9413dd59f0f63759704b77ae156') in 0.001280 seconds 
Refreshing native plugins compatible for Editor in 0.48 ms, found 3 plugins.
Plugins: Couldn't open <PROJECT_ROOT>/Assets/ThirdParty/NativeFileSO/Plugins/macOS/NativeFileSOMac.bundle/Contents/MacOS/NativeFileSOMac, error: dlopen(<PROJECT_ROOT>/Assets/ThirdParty/NativeFileSO/Plugins/macOS/NativeFileSOMac.bundle/Contents/MacOS/NativeFileSOMac, 0x0002): tried: '<PROJECT_ROOT>/Assets/ThirdParty/NativeFileSO/Plugins/macOS/NativeFileSOMac.bundle/Contents/MacOS/NativeFileSOMac' (code signature in <2CB3A75C-58B5-3700-A6E2-CA1E3AE6A9E0> '<PROJECT_ROOT>/Assets/ThirdParty/NativeFileSO/Plugins/macOS/NativeFileSOMac.bundle/Contents/MacOS/NativeFileSOMac' not valid for use in process: Trying to load an unsigned library), '/System/Volumes/Preboot/Cryptexes/OS<PROJECT_ROOT>/Assets/ThirdParty/NativeFileSO/Plugins/macOS/NativeFileSOMac.bundle/Contents/MacOS/NativeFileSOMac' (no such file), '<PROJECT_ROOT>/Assets/ThirdParty/NativeFileSO/Plugins/macOS/NativeFileSOMac.bundle/Contents/MacOS/NativeFileSOMac' (code signature in <2CB3A75C-58B5-3700-A6E2-CA1E3AE6A9E0> '<PROJECT_ROOT>/Assets/ThirdParty/NativeFileSO/Plugins/macOS/NativeFileSOMac.bundle/Contents/MacOS/NativeFileSOMac' not valid for use in process: Trying to load an unsigned library)

similarly, if I select Load on startup in plugin load settings in the inspector I also get:

Refreshing native plugins compatible for Editor in 5.43 ms, found 3 plugins.
Plugins: Couldn't open Assets/ThirdParty/NativeFileSO/Plugins/macOS/NativeFileSOMac.bundle/Contents/MacOS/NativeFileSOMac, error: dlopen(Assets/ThirdParty/NativeFileSO/Plugins/macOS/NativeFileSOMac.bundle/Contents/MacOS/NativeFileSOMac, 0x0002): tried: 'Assets/ThirdParty/NativeFileSO/Plugins/macOS/NativeFileSOMac.bundle/Contents/MacOS/NativeFileSOMac' (code signature in <2CB3A75C-58B5-3700-A6E2-CA1E3AE6A9E0> '<PROJECT_ROOT>/Assets/ThirdParty/NativeFileSO/Plugins/macOS/NativeFileSOMac.bundle/Contents/MacOS/NativeFileSOMac' not valid for use in process: Trying to load an unsigned library), '/System/Volumes/Preboot/Cryptexes/OSAssets/ThirdParty/NativeFileSO/Plugins/macOS/NativeFileSOMac.bundle/Contents/MacOS/NativeFileSOMac' (no such file), '/Applications/Unity/Hub/Editor/2021.3.13f1/Unity.app/Contents/Frameworks/Assets/ThirdParty/NativeFileSO/Plugins/macOS/NativeFileSOMac.bundle/Contents/MacOS/NativeFileSOMac' (no such file), '/Applications/Unity/Hub/Editor/2021.3.13f1/Unity.app/Contents/Frameworks/Assets/ThirdParty/NativeFileSO/Plugins/macOS/NativeFileSOMac.bundle/Contents/MacOS/NativeFileSOMac' (no such file), '/usr/lib/Assets/ThirdParty/NativeFileSO/Plugins/macOS/NativeFileSOMac.bundle/Contents/MacOS/NativeFileSOMac' (no such file, not in dyld cache), 'Assets/ThirdParty/NativeFileSO/Plugins/macOS/NativeFileSOMac.bundle/Contents/MacOS/NativeFileSOMac' (code signature in <2CB3A75C-58B5-3700-A6E2-CA1E3AE6A9E0> '<PROJECT_ROOT>/Assets/ThirdParty/NativeFileSO/Plugins/macOS/NativeFileSOMac.bundle/Contents/MacOS/NativeFileSOMac' not valid for use in process: Trying to load an unsigned library), '<PROJECT_ROOT>/Assets/ThirdParty/NativeFileSO/Plugins/macOS/NativeFileSOMac.bundle/Contents/MacOS/NativeFileSOMac' (code signature in <2CB3A75C-58B5-3700-A6E2-CA1E3AE6A9E0> '<PROJECT_ROOT>/Assets/ThirdParty/NativeFileSO/Plugins/macOS/NativeFileSOMac.bundle/Contents/MacOS/NativeFileSOMac' not valid for use in process: Trying to load an unsigned library), '/System/Volumes/Preboot/Cryptexes/OS<PROJECT_ROOT>/Assets/ThirdParty/NativeFileSO/Plugins/macOS/NativeFileSOMac.bundle/Contents/MacOS/NativeFileSOMac' (no such file), '<PROJECT_ROOT>/Assets/ThirdParty/NativeFileSO/Plugins/macOS/NativeFileSOMac.bundle/Contents/MacOS/NativeFileSOMac' (code signature in <2CB3A75C-58B5-3700-A6E2-CA1E3AE6A9E0> '<PROJECT_ROOT>/Assets/ThirdParty/NativeFileSO/Plugins/macOS/NativeFileSOMac.bundle/Contents/MacOS/NativeFileSOMac' not valid for use in process: Trying to load an unsigned library)

and still the same outcome :( image

also tried computer restart and updating unity to 2021.3.18f1, just in case, but still no luck

not valid for use in process: Trying to load an unsigned library) seems like this is the most likely reason, not sure why allowing the use in security and privacy settings isn't reflected in unity ;/

are you maybe using third party / embedded frameworks in the macOS plugin? this is the only similar thing I found

btw, opening in intel version of the editor still works just fine 🤷

danieldownes commented 4 months ago

Got this working in builds on M1 / ARM. However still get the DllNotFoundException in the Editor. Another thing to be careful of, you should download the latest 1.0.5 version from github releases. The latest version of the package is not included in the repo download. This caused some confusion for me for a while as I was on .4 accedently. Finally make sure to change the NativeFileSOMac file from the inspector as its set to "Intel 64-bit", and should be "Any CPU".