How to export Unity App into flutter?

I am having a hard time exporting my Unity Application into Flutter.

When user press this specific button, it will open the Unity Application I made, yet it seems too complicated on my end, I keep having errors. I can’t figure it out.

is there any easy way to do it?

Thank you in advance.

Did you work through all the integration steps as specified by Flutter? I see a huge stack of steps when I google for it and yet your post doesn’t state that you did any of them or in any particular order.

You also also don’t mention where the problem is or what the errors are, or which step of the integration process gave you errors.

How to report your problem productively in the Unity3D forums:

This is the bare minimum of information to report:

  • what you want
  • what you tried
  • what you expected to happen
  • what actually happened, log output, variable values, and especially any errors you see
  • links to actual Unity3D documentation you used to cross-check your work (CRITICAL!!!)

The purpose of YOU providing links is to make our job easier, while simultaneously showing us that you actually put effort into the process. If you haven’t put effort into finding the documentation, why should we bother putting effort into replying?

If you post code, only post the relevant code and always use the format button above. Do not post photographs of code.

If you have no idea, then it is time to fix that first by debugging what you have until you understand what you are doing. This step is not optional.

By debugging you can find out exactly what your program is doing so you can fix it.

Use the above techniques to get the information you need in order to reason about what the problem is.

You can also use Debug.Log(...); statements to find out if any of your code is even running. Don’t assume it is.

Once you understand what the problem is, you may begin to reason about a solution to the problem.

Remember with Unity the code is only a tiny fraction of the problem space. Everything asset- and scene- wise must also be set up correctly to match the associated code and its assumptions.

I figured out how to export it properly but now I can’t properly run my Flutter App with a exported Unity Application. I followed all instructions on flutter_unity_widget | Flutter package.

yet I am still having issues with my NDK Version on Unity.

On Flutter it’s forcing me to use NDK Version 27, but version 27 is not supported and not recommended on Unity. I am currently using Version 23.

This what happens when i use Version 23:

FAILURE: Build failed with an exception.

* Where:
Build file 'C:\Users\JERICHO\Desktop\MainRoomScape\android\build.gradle.kts' line: 20

* What went wrong:
A problem occurred configuring project ':app'.
> [CXX1104] NDK from ndk.dir at C:\Program Files\Unity\Hub\Editor\2022.3.59f1\Editor\Data\PlaybackEngines\AndroidPlayer\NDK had version [23.1.7779620] which disagrees with android.ndkVersion [27.0.12077973]

This what happens when i use Version 27:

Your project is configured with Android NDK 23.1.7779620, but the following plugin(s) depend on a different Android NDK version:
- flutter_plugin_android_lifecycle requires Android NDK 27.0.12077973
- flutter_unity_widget requires Android NDK 27.0.12077973
- webview_flutter_android requires Android NDK 27.0.12077973
Fix this issue by using the highest Android NDK version (they are backward compatible).
Add the following to C:\Users\JERICHO\Desktop\MainRoomScape\android\app\build.gradle.kts:

    android {
        ndkVersion = "27.0.12077973"
        ...
    }

build.gradle.kts

plugins {
    id("com.android.application")
    id("kotlin-android")
    // The Flutter Gradle Plugin must be applied after the Android and Kotlin Gradle plugins.
    id("dev.flutter.flutter-gradle-plugin")
}

android {
    namespace = "com.example.mainroomscape"
    compileSdk = flutter.compileSdkVersion
    ndkVersion = "27.0.12077973"

    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_11
        targetCompatibility = JavaVersion.VERSION_11
    }

    kotlinOptions {
        jvmTarget = JavaVersion.VERSION_11.toString()
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId = "com.example.mainroomscape"
        // You can update the following values to match your application needs.
        // For more information, see: https://flutter.dev/to/review-gradle-config.
        minSdk = 24
        targetSdk = flutter.targetSdkVersion
        versionCode = flutter.versionCode
        versionName = flutter.versionName
    }

    buildTypes {
        release {
            // TODO: Add your own signing config for the release build.
            // Signing with the debug keys for now, so `flutter run --release` works.
            signingConfig = signingConfigs.getByName("debug")
        }
    }
}

flutter {
    source = "../.."
}

dependencies {
    implementation(project(":unityLibrary"))
}

and when i tried to install NDK 27, this shows:

This may be your biggest hurdle… I’m not sure what the mix-n-match Android NDK rules are.

What about using an older version of Flutter that works with NDK 23?

OR… did you try Unity on 27? It might “just work…”

There may be some gradle-y Android stuff you could set up too, to bridge different-NDK-built chunks, either by librarifying or DLL-ifying them…

Here’s more generic stuff, including Gradle goodness at the bottom:

How to troubleshoot build failures:

Obviously, if there is actionable data, clues or information within any of the errors, fix those problems. Each error entry may have more information than can fit in the console log so select each error and read the expanded view below it.

If that gives you nothing worthwhile (look to Google! You’re never the first one!), then…

First, make a blank project with a single blank scene and prove that it builds successfully.

If the blank project does NOT build, go fix your Unity installation or your other tools, such as Android SDK, NDK, JDK, etc. It may even be necessary to change to a different version of Unity3D. It is generally best to stay with LTS versions of Unity3D.

Until you can build a blank project to the target platform, don’t fiddle with anything else.

Once you can build a blank project, now bisect the problem by bringing over parts of your current project and building it one subsystem at a time, perhaps stubbing things out that might trigger compiler errors.

Most often things that prevent building are misconfigured or incorrectly-installed or incompatible third-party libraries such as Firebase or AdMob or IronSource.

Once you identify the subsystem, go to the documentation for it and make sure you are doing it correctly.

It may also be helpful to work through a tutorial or two for whatever subsystem is making the build fail.

Android build not building:

Circa July 2022 here have been reports of Unity’s installer failing to install the Android Tools.

Here was how I brought up Unity2020.3.41 and the Android SDK 31 on October 30, 2022 (edited on August 23, 2023 to include Android SDK 33…) (and again for SDK34):

Android Gradle errors and other related stuff:

Android SDK35 stuff: