ialex32x / unity-jsb

It brings Javascript runtime capability to Unity3D by integrating QuickJS.
MIT License
337 stars 41 forks source link

Errors with Building #39

Closed blamay closed 3 years ago

blamay commented 3 years ago

Things are working great when I play the SampleScene normally, but when I 'Build and Run' the game I see the following error. Is there a step that I'm missing before building? Screen Shot 2021-07-28 at 8 57 18 AM

Also, if I use "Generate Bindings and Type Definitions", I'm able to Play the scene but when I build I get some errors. Screen Shot 2021-07-28 at 9 11 07 AM

ialex32x commented 3 years ago

Hi blamay, the first error is because the reflectbind mode is used by default. It's only available in editor runtime (at present). The second error is caused by the difference between editor and player runtime of Unity's dll. You could try to block the specific type (or type member) in CustomBinding process. If it still reports errors, I'll continue to follow up

blamay commented 3 years ago

Thank you very much for your reply. If I turn off reflectbind mode, generate bindings, and remove UnityEngine_UI_GraphicRebuildTracker.cs, then I'm able to build without error and run JS. This is on unity version 2019.1.9f1 that comes with the clone.

But if I upgrade the project to 2020.3.13f1 or import jsb into an existing 2020.3.13f1 project, then I get this System.DllNotFoundException: quickjs error after building. Things still work in the editor though. Do you know how I can fix this?

DllNotFound

ialex32x commented 3 years ago

It seems the player runtime can not load the correct dll lib. Which target platform do you use? Firstly, check if the dll's target platform and architecture in Unity are correct, they will be scrambled in some situations. (the editor and the built app use different dll)

blamay commented 3 years ago

I'm hoping to build for PC, Mac, iOS and Android, but this was targeting macOS and 'Intel 64-bit + Apple silicon' Architecture. If I change Architecture to just 'Intel 64-bit', then the build works. Thanks for your help!

blamay commented 3 years ago

Using Intel 64-bit only is working for me for now, but it would be nice to have Apple silicon builds working at some point.

ialex32x commented 3 years ago

OK, I'll check how to build for Apple silicon.

ialex32x commented 3 years ago

I tried on macos with M1 chip. It seems ok with "Intel 64-bit and Apple silicon" settings for mac build. Could you give more details on it? Which version of Unity Editor are you using? And which commit of master branch did you choose to build?

blamay commented 3 years ago

Thanks for giving it a try! That's encouraging that it worked for you on M1. I'm not actually using an M1 chip though, my MBP is a 2019 with an Intel chip. 'Intel 64-bit + Apple silicon' implies that it should work for both though.

This was on 2020.3.13f1 that I mentioned above. I'm not sure which commit it was but it was freshly cloned 7 days ago when I made the issue. XCode version 12.5.

I just downloaded 2020.3.14f1 and re-cloned jsb at c9076d7 to double check.

Steps:

  1. Created new unity project on 2020.3.14f1

  2. Cloned jsb master at c9076d7

  3. Moved everything from jsb into the new project except for the Packages folder and the ProjectSettings folder

  4. Ran npm install

  5. Loaded Examples/Scenes/SampleScene with game_demo

  6. Turned off reflect-bind mode

  7. Generated Bindings & Type Definitions

  8. Comment out compilation errors in compiled generated code:

    Assets/Generated/OSX/UnityEngine_ParticleSystemRenderer.cs(1151,32): error CS1061: 'ParticleSystemRenderer' does not contain a definition for 'supportsMeshInstancing' and no accessible extension method 'supportsMeshInstancing' accepting a first argument of type 'ParticleSystemRenderer' could be found (are you missing a using directive or an assembly reference?)

    Assets/Generated/OSX/UnityEngine_UI_DefaultControls.cs(281,17): error CS0200: Property or indexer 'DefaultControls.factory' cannot be assigned to -- it is read only

  9. Built the game targeting macOS and 'Intel 64-bit + Apple silicon' Architecture

  10. Run the build and see type initializer exception in the console. System.DllNotFoundException: quickjs from the screenshot above.

If I change 'Intel 64-bit + Apple silicon' to just 'Intel 64-bit' and build, then everything works perfectly.

ialex32x commented 3 years ago

Hi blamay, I've tried and checked again. It works after updating the platform settings of quickjs.bundle. And I omitted the type members causing compilation errors you've mentioned. You can update and test again.

blamay commented 3 years ago

After pulling the latest changes from master, there are no longer compilation errors from Generated files, and JS works when targeting 'Intel 64-bit + Apple silicon'!! Thank you so much for fixing this so quickly! This is a great project.

blamay commented 3 years ago

I do have another question though. Is it currently possible to perform JS Bridge > Generate Bindings and Type Definition from CLI? It would be nice to be able to automate that for builds.

ialex32x commented 3 years ago

I'm glad to hear that, thanks 😄 Yes, you can do it through unity command line mode but maybe two build phases are required, the first for generating the glue code, and the second for the general build (I haven't checked this).

For example:

xxx\path\to\your\unity_executable -batchmode -nographics -executeMethod QuickJS.Unity.UnityHelper.GenerateBindingsAndTypeDefinition -projectPath path\to\your\project -quit

REM -nographics is not required when you are using macos or linux