Zenject icon indicating copy to clipboard operation
Zenject copied to clipboard

Android exception

Open svermeulen opened this issue 6 years ago • 8 comments

https://github.com/modesttree/Zenject/issues/631

svermeulen avatar May 03 '19 17:05 svermeulen

That's interesting, that sounds more like the kind of error you would get due to IL2CPP code-stripping, but you aren't using IL2CPP

svermeulen avatar May 03 '19 17:05 svermeulen

I tried to reproduce this using the sample projects in both Unity 2019.1.0f2 and Unity 2018.3.12f1 but it worked as expected

svermeulen avatar May 04 '19 21:05 svermeulen

I've updated to Extenject 8.0.1 and still getting the same error. Its definitely a Mono NET 4.5 build not IL2CPP. If it is code stripping, which I thought it might be, is there some way I can mark it as do not remove? There isn't actually a constructor defined in that class but I guess it should automatically be created

realworld666 avatar May 07 '19 09:05 realworld666

Yeah I remember getting that error in the past with IL2CPP sometimes. The workaround was to not only define a constructor but also add the [Inject] attribute. And since InjectAttribute inherits from PreserveAttribute, IL2CPP is guaranteed to not strip it. But I didn't think that workaround was necessary anymore since I thought constructors are included by default now. Also, I thought code stripping was only something that occurred with IL2CPP, so I can't really explain this. If you can provide a minimal example I can look into it further though

svermeulen avatar May 08 '19 03:05 svermeulen

Any news about this issue?

kekchpek avatar Jun 08 '20 09:06 kekchpek

The workaround solution that works for me was add default constructor for all my non MonoBehaviour classes manualy, and add a Inject attribute for them. Also I did the same thing for some classes into Zenject.

kekchpek avatar Jun 08 '20 10:06 kekchpek

I needed to add empty constructors with [Inject] to ZenjectManagersInstaller, SceneContextRegistryAdderAndRemover, SceneContextRegistry. Android build with Mono, Unity 2020.3.3f1 with Zenject 9.20.

TheAnosmic avatar May 06 '21 19:05 TheAnosmic

The code is probably erased (unused code is deleted) during the build. Usually this is code that is not called directly, but through reflection. This happens on the Inject attribute. It is necessary to look for something like Strip Code Level in the Project Setting -> Player -> Other settings and select the most minimal one or disable it altogether.

IvanM71 avatar Jul 21 '22 12:07 IvanM71