Description
Solutions Implemented for Compatibility with Unity 2021 and Higher Versions:
-
Issue: Execution failed for task ':unityLibrary:BuildIl2CppTask'.
- Error: NDK is not installed
Solution: In the
unityLibrary/build.gradle
file, comment out the following line:android { //ndkPath "C:/Program Files/Unity/Hub/Editor/2022.3.14f1/Editor/Data/PlaybackEngines/AndroidPlayer/NDK" ... }
-
Issue: NoSuchFieldError - No "Ljava/lang/Object;" field "mUnityPlayer" in class "Lcom/example/app/MainActivity;" or its superclasses.
Solution: Refer to the comment in this GitHub issue for a potential fix: Flutter Unity Widget Issue #836 Comment -
Issue: E/AndroidRuntime(14114): java.lang.NoSuchMethodError: no non-static method "Lcom/xraph/plugin/flutter_unity_widget/CustomUnityPlayer;.hidePreservedContent()V"
Solution: In the library directory
flutter-unity-view-widget
, modify the fileflutter-unity-view-widget\android\src\main\kotlin\com\xraph\plugin\flutter_unity_widget\CustomUnityPlayer.kt
by adding the following method to theCustomUnityPlayer
class:@SuppressLint("NewApi") class CustomUnityPlayer(context: Activity, upl: IUnityPlayerLifecycleEvents?) : UnityPlayer(context, upl) { companion object { internal const val LOG_TAG = "CustomUnityPlayer" } // Add this method fun hidePreservedContent() { // Implement content hiding logic here // Example: // this.setVisibility(View.GONE); } ... }
-
If Unity is still not displayed after the above steps:
- In Flutter, set the
useAndroidViewSurface
parameter totrue
in your UnityWidget widget:
UnityWidget( useAndroidViewSurface: true, // Other parameters... )
- In Flutter, set the
These solutions are intended to address compatibility issues encountered with Unity 2021 and higher versions when integrating with the Flutter Unity Widget plugin.