mcpiroman / UnityNativeTool

Allows to unload native plugins in Unity3d editor
MIT License
184 stars 19 forks source link

Testing on Windows 10, deploy to Android #24

Closed teotigraphix closed 4 years ago

teotigraphix commented 4 years ago

Nice library! I have been using this for dev on Windows and finally got around trying to build for Android.

I have my Android .so libs that run just fine on devices but I am wondering what I am doing wrong to be able to test on the PC and then build for Android.

Can this project even work like this? Use my custom library dlls for testing on Windows, then in the same project/scene be able to switch to the Android target and build without error?

I already have an abstract audio engine that runs fine on Android(runtime switch for implementation) using a lib .so but it seems like I am missing the part where I tell Unity, this is only for the Editor on Windows.

Tried also strategically setting all dlls to only be editor but that does not seem to matter. Here is the stack;

image

Thanks!

mcpiroman commented 4 years ago

Hi, this tool only runs on x86 (or x64) machines and I assume your Android device is on ARM, thus it won't work. (I also assume that you're trying to actually use it, i.e. be able to reload .so libraries while running the game on Android; if you want to test them on Windows and just deploy to Android it should obviously work.)

I doubted anyone will ever want to do such thing and apparently I was wrong :). This capability can be achieved, most probably by migrating detouring from Harmony clone to MonoMod, which I also considered some time ago (and this was one of the reasons), however this wouldn't be trivial because MonoMod depends on Mono.Cecil and I don't want to have additional dependencies.

If however by any chance your device has x86 based processor, then its support should be in theory very easy, just a matter of mixing couple compilator directives (probably UNITY_ANDROID).

teotigraphix commented 4 years ago

I knew this was going to take some explanation. :)

I am not trying to run any of this project on Android. So I guess I am learning something today, even though I don't want any of this code on an Android device, there is no way to use the same project for the build (PC == testing && Android == no UnityNativeTool at all)?

Literally all I am using your lib for is loading the win dlls that use the exact same C++ for .so Android compile. These are not C# dlls but compiled C++ DLL with extern C.

mcpiroman commented 4 years ago

Ah yes, now I get it. I though the configuration you described should run out of the box, but now I see there is a bug in platform dependent compilation that obviously denies that. So yeah, I'll fix that. Thanks for reporting!

teotigraphix commented 4 years ago

bug in platform dependent compilation that obviously denies that.

Yes, I was about to start throwing #if all over but I thought that wasn't wise since I don't know the code. :)

Thanks a lot!

mcpiroman commented 4 years ago

You may test it now. I haven't tested myself, because I don't have appropriate Unity build environment installed ATM, but I guess it should work.

teotigraphix commented 4 years ago

That fixed the compile issue, thanks!