Skip to content

Compatibility Fixes for Unity 2021 and Above in Flutter Unity Widget Plugin #903

Open
@mr-aydemir

Description

@mr-aydemir

Solutions Implemented for Compatibility with Unity 2021 and Higher Versions:

  1. 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"
    ...
    }
  2. 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

  3. 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 file flutter-unity-view-widget\android\src\main\kotlin\com\xraph\plugin\flutter_unity_widget\CustomUnityPlayer.kt by adding the following method to the CustomUnityPlayer 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);
        }    
    ...
    }
  4. If Unity is still not displayed after the above steps:

    • In Flutter, set the useAndroidViewSurface parameter to true in your UnityWidget widget:
    UnityWidget(
      useAndroidViewSurface: true,
      // Other parameters...
    )

These solutions are intended to address compatibility issues encountered with Unity 2021 and higher versions when integrating with the Flutter Unity Widget plugin.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DocumentationDocumentation issue (readme or examples)

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions