Integrate Unity as a Library via Dynamic Feature Modules in Android
I currently try to integrate Unity as a Library for one part of a native app. The basic integration works quite okay (despite some issues with back navigation killing the whole process and stuff like that).
Now I wanted to use Androids Dynamic Feature Modules to provide the Unity part on demand because it is quite big compared to the rest of the app and not every user needs the functionality.
So I moved all the dependencies into the new created DFM as well as a custom Activity which inherits from the UnityPlayerActivity. At runtime it crashes immediately and I can see stuff like the following in my Logcat:
E/Unity: Unable to find type [UnityEngine.CoreModule.dll]Unity.Collections.DeallocateOnJobCompletionAttribute
E/Unity: Unable to find type [UnityEngine.CoreModule.dll]Unity.Collections.LowLevel.Unsafe.NativeContainerAttribute
E/Unity: Unable to find type [UnityEngine.CoreModule.dll]Unity.Collections.LowLevel.Unsafe.NativeContainerIsAtomicWriteOnlyAttribute
E/Unity: Unable to find type [UnityEngine.CoreModule.dll]Unity.Collections.LowLevel.Unsafe.NativeContainerIsReadOnlyAttribute
E/Unity: Unable to find type [UnityEngine.CoreModule.dll]Unity.Collections.LowLevel.Unsafe.NativeContainerNeedsThreadIndexAttribute
The log is full of that so it seems something can't be find correctly. Without using the DFM approach it's actually working, so it does not seem to be an issue of the Unity component itself.
I also tried workarounds mentioned on the internet like adding a bin/Data/Managed folder to the assets folder but nothing helped.
Did anyone already successfully integrate an AAR built out of Unity into a DFM?
Answer by PhilNow · Oct 08, 2021 at 08:42 AM
It does not seem to have anything to do with the DFM at this point. I used the Android 12 beta since a few days and my working test was still on Android 11. So I downgraded my phone again and it is running with the same configuration. So this issues are most likely related to Android 12.
Your answer
Follow this Question
Related Questions
How can we integrate more than one unity module in Android Studio? 0 Answers
IL2CPP Android build with custom static libraries linked with GNU STL static library 0 Answers
UnsatisfiedLinkError for android library 0 Answers
UnityPlayer packaged as an Android library module? 0 Answers
Importing an aar crashed my application - Unity 5.5.0f3 0 Answers