- Notifications
You must be signed in to change notification settings - Fork576
Embeddable unity game engine view for Flutter. Advance demo herehttps://github.com/juicycleff/flutter-unity-arkit-demo
License
juicycleff/flutter-unity-view-widget
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Flutter unity 3D widget for embedding unity in flutter. Now you can make awesome gamified features of your app in Unity and get it rendered in a Flutter app both in fullscreen and embeddable mode. Works great onAndroid, iPad OS, iOS, Web
.
- Use Windows or Mac to export and build your project.
Users on Ubuntu have reported a lot of errors in the Unity export. - Emulator support is limited and requires special setup. Please use a physical device for Android and iOS.
- Supports Unity 2019.4.3 up to 2022.3.x, we recommend the latest 2022.3 LTS.
Checkthis github issue for support of Unity 6. - Use only OpenGLES3 as Graphics API on Android for AR compatibility.
- Windows isn't supported because of the lack ofFlutter PlatformView support.
Need me to respond, tag meRex Isaac Raphael.
This plugin expects you to atleast know how to use Unity Engine. If you have issues with how unity widget is presented, you can please modify your unity project build settings as you seem fit.
Moving forward, versioning of the package will change to match unity releases after proper test. Mind you this does not mean the packageis not compatible with other versions, it just mean it's been tested to work with a unity version.
This plugin requires Flutter >= 3.16.0.
First depend on the library by adding this to your packagespubspec.yaml
:
dependencies:flutter_unity_widget:^2022.2.1# use the latest compatible version
Now inside your Dart code you can import it.
import'package:flutter_unity_widget/flutter_unity_widget.dart';
You will need to open and export a Unity project, even for running the example. Your build will fail if you only include the widget in Flutter!
30 fps gifs, showcasing communication between Flutter and Unity:
In the tutorial below, there are steps specific to each platform, denoted by a ℹ️ icon followed bythe platform name (Android or iOS). You can click on its icon to expand it.
An existing Flutter project (if there is none, you cancreate a new one)
An existing Unity project (if there is none, you cancreate a new one).
A
fuw-XXXX.unitypackage
file, found in theunitypackages folder.Try to use the most recent unitypackage available.
If you want to publish your app for Android or iOS, you need to satisfy certain Unity version requirements.
iOS
Apple'sprivacy manifest requirements need a minimal Unity version of:
- 2021.3.35+
- 2022.3.18+
- 6000.0.0+
Android
Starting November 1st, 2025, all new apps and updates to existing apps submitted to Google Play and targeting Android 15+ devices must support 16 KB page sizes.
This requiresUnity versions:
- 2021.3.48+ (Enterprise and Industry only)
- 2022.3.56+
- 6000.0.38+
These instructions assume you are using a new Unity project. If you open the example project from this repository, you can move on to the next sectionUnity Exporting.
- Create a folder namedunity in your Flutter project folder and move the Unity project into there.
The Unity export will modify some files in the/android
and/ios
folders of your flutter project. If your Unity project is in a different location the export might (partially) fail.
The expected path is/unity/project-name/...
Make sure you have downloaded afuw-XXXX.unitypackage file mentioned inprerequisites.
Using Unity (hub), open the Unity project.Go toAssets > Import Package > Custom Package and select the downloadedfuw-XXXX.unitypackage file. Click onImport.
Go toFile > Build Settings > Player Settingsand change the following under theOther settings > Configuration section:
InScripting Backend, change to IL2CPP
(Android)Target Architectures, select ARMv7 and ARM64
(Android) For the best compatibility setActive Input Handling to
Input Manager (Old)
orBoth
.
(The new input system has some issues with touch input on Android)(iOS) SelectTarget SDK depending on where you will run your app (simulator or physical device).
We recommend starting with a physical device and theDevice SDK
setting, due to limited simulator support.(Web) SetPublishing settings > Compression format to Brotli or Disabled.
Some users report that Unity gets stuck on the loading screen with the Gzip setting, due to MIME type errors.
- InFile > Build Settings, make sure to have at least 1 scene added to your build.
Some options in theBuild settings window get overridden by the plugin's export script.Attempting to change settings likeDevelopment Build
,Script Debugging
andExport project
in this window will not make a difference.If you end up having to change a build setting that doesn't seem to respond, take a lookat the export scriptFlutterUnityIntegration\Editor\Build.cs
.
After importing the unitypackage, you should now see aFlutter option at the top of the Unity editor.
Click onFlutter and select the appropriate export option:
- For android useExport Android Debug orExport Android Release.
This will export toandroid/unityLibrary. - For iOS useExport iOS Debug orExport iOS Release.
This will export toios/UnityLibrary. - Do not useFlutter > ExportPlatform plugin as it was specially added to work with
flutter_unity_cli
for larger projects.
If you use git, you will probably want to add these unityLibrary folders to your gitignore file.These folders can get huge and are not guaranteed to work on another computer.
Proceed to the next section to handle iOS and Android specific setup after the export.
After exporting Unity, you will need to make some small changes in your iOS or Android project.
You will likely need to do thisonly once. These changes remain on future Unity exports.
ℹ️Android
- Setting the Android NDK
- If you have Unity and Flutter installed on the same machine, the easiest approach is to use the path of the NDK Unity uses. You can find the path to the NDK in Unity under
Edit -> Preferences -> External Tool
:
- Copy the path and paste it into your flutter project at
android/local.properties
asndk.dir=
.
(For windows you will need to replace\
with\\
.)
Don't simply copy and paste this, make sure it the path matches your Unity version!
// macndk.dir=/Applications/Unity/Hub/Editor/2020.3.19f1/PlaybackEngines/AndroidPlayer/NDK // windowsndk.dir=C:\\Program Files\\Unity\\Hub\\Editor\\2021.3.13f1\\Editor\\Data\\PlaybackEngines\\AndroidPlayer\\NDK
- With the above setup, you shouldn't have to define any NDK version or setting in gradle files.
If you don't have Unity on the device making your Flutter buids, you can instead define it inandroid/app/build.gradle
.
android { ndkVersion"21.3.6528147"}
- To find the exact version that Unity uses, check
source.properties
at the NDK path described above.
Depending on your gradle version, you might need to make sure the
minSdkVersion
set inandroid\app\build.gradle
matches the version that is set in Unity.
Check theMinimum API Level setting in the Unity player settings, and match that version.(optional) Fixing Unity plugins.
The Unity widget will function without this step, but some Unity plugins like ArFoundation will throwmUnityPlayer
errors on newer Unity versions.This is needed for Unity 2020.3.46+, 2021.3.19 - 2021.3.20 and 2022.2.4 - 2022.3.18.
This requires a flutter_unity_widget version that is newer than 2022.2.1.
- 3.1. Open the
android/app/build.gradle
file and add the following:
dependencies { // build.gradle+ implementation project(':flutter_unity_widget') // build.gradle.kts (Flutter 3.29+)+ implementation(project(":flutter_unity_widget")) }
3.2. Edit your android MainActivity file.
The default location for Flutter isandroid/app/src/main/kotlin/<app identifier>/MainActivity.kt
.If you use the default flutter activity, change it to inherit
FlutterUnityActivity
:
// MainActivity.kt+ import com.xraph.plugin.flutter_unity_widget.FlutterUnityActivity;+ class MainActivity: FlutterUnityActivity() {- class MainActivity: FlutterActivity() {
- 3.2. (alternative) If you use a custom or modified Activity, implement the
IFlutterUnityActivity
interface instead.
// MainActivity.kt// only do this if your activity does not inherit FlutterActivityimportcom.xraph.plugin.flutter_unity_widget.IFlutterUnityActivity;classMainActivity:CustomActivity(), IFlutterUnityActivity {// unity will try to read this mUnityPlayer property @JvmFieldvar mUnityPlayer: java.lang.Object?=null;// implement this function so the plugin can set mUnityPlayeroverridefunsetUnityPlayer(unityPlayer: java.lang.Object?) { mUnityPlayer= unityPlayer; }}
- The Unity export script automatically sets the rest up for you. You are done with the Android setup.
But if you want to manually set up the changes made by the export, continue.
Optional manual Android setup
- Open theandroid/settings.gradle file and change the following:
// build.gradle+ include ":unityLibrary"+ project(":unityLibrary").projectDir = file("./unityLibrary")// build.gradle.kts (Flutter 3.29+)+ include(":unityLibrary")+ project(":unityLibrary").projectDir = file("./unityLibrary")
- Open theandroid/app/build.gradle file and change the following:
dependencies { // app/build.gradle+ implementation project(':unityLibrary') // app/build.gradle.kts (Flutter 3.29+)+ implementation(project(":unityLibrary")) }
- open theandroid/build.gradle file and change the following:
allprojects { repositories {+ flatDir { // build.gradle+ dirs "${project(':unityLibrary').projectDir}/libs" // build.gradle.kts (Flutter 3.29+)+ dirs(file("${project(":unityLibrary").projectDir}/libs"))+ } google() mavenCentral() }}
- If you need to build a release package, open theandroid/app/build.gradle file and change the following:
buildTypes { release { signingConfig signingConfigs.debug }+ debug {+ signingConfig signingConfigs.debug+ }+ profile {+ signingConfig signingConfigs.debug+ }+ innerTest {+ matchingFallbacks = ['debug', 'release']+ }+ }
The code above use the
debug
signConfig for all buildTypes, which can be changed as you well if you need specify signConfig.
- If you use
minifyEnabled true
in yourandroid/app/build.gradle file, open theandroid/unityLibrary/proguard-unity.txt and change the following:
+ -keep class com.xraph.plugin.** {*;}
- If you want Unity in it's own activity as an alternative, open theandroid/app/src/main/AndroidManifest.xml and change the following:
+ <activity+ android:name="com.xraph.plugin.flutter_unity_widget.OverrideUnityActivity"+ android:theme="@style/UnityThemeSelector"+ android:screenOrientation="fullSensor"+ android:launchMode="singleTask"+ android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|uiMode|screenSize|smallestScreenSize|fontScale|layoutDirection|density"+ android:hardwareAccelerated="false"+ android:process=":Unity">+ <meta-data android:name="com.xraph.plugin.flutter_unity_widget.OverrideUnityActivity" android:value="true" />+ </activity>
ℹ️iOS
- Open theios/Runner.xcworkspace (workspace, not the project) file in Xcode, right-click on the Navigator (not on an item), go toAdd Files to "Runner" and addtheios/UnityLibrary/Unity-Iphone.xcodeproj file.

- (Optional) Select theUnity-iPhone/Data folder and change the Target Membership for Data folder to UnityFramework.

3.1. If you're using Swift, open theios/Runner/AppDelegate.swift file and change the following:
import UIKit import Flutter+ import flutter_unity_widget @UIApplicationMain @objc class AppDelegate: FlutterAppDelegate { override func application( _ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? ) -> Bool {+ InitUnityIntegrationWithOptions(argc: CommandLine.argc, argv: CommandLine.unsafeArgv, launchOptions) GeneratedPluginRegistrant.register(with: self) return super.application(application, didFinishLaunchingWithOptions: launchOptions) } }
3.2. If you're using Objective-C, open theios/Runner/main.m file and change the following:
+ #import "flutter_unity_widget.swift.h" int main(int argc, char * argv[]) { @autoreleasepool {+ InitUnityIntegration(argc, argv); return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); } }
- Add theUnityFramework.framework file as a library to the Runner project.

Unity plugins that make use of native code (Vuforia, openCV, etc.) might need to be added to Runner like UnityFramework.
Check the contents of the/ios/UnityLibrary/Frameworks/
directory. Any<name>.framework
located in (subdirectories of) this directory is a framework that you can add to Runner.Make sure pods are installed after your Unity export, either using
flutter run
or by runningpod install
in the ios folder.If you use Xcode 14 or newer, and Unity older than 2021.3.17f1 or 2022.2.2f1, your app might crash when running from Xcode.
Disable theThread Performance Checker
feature in Xcode to fix this.
- In Xcode go toProduct > Scheme > Edit Scheme...
- Now WithRun
selected on the left, got to theDiagnostics
tab and uncheck the checkbox forThread Performance Checker
.
The following setup for AR is done after making an export from Unity.
Warning: Flutter 3.22 has introduced a crash when using AR on Android < 13#957
ℹ️AR Foundation Android
Check the version of the
XR Plugin Management
in the Unity package manager. Versions4.3.1 - 4.3.3
contain a bug that breaks Android exports.
Make sure to use a version <=4.2.2
or >=4.4
.
You might have to manually change the version in<unity project>/Packages/manifest.json
for"com.unity.xr.management"
.You can check the
android/unityLibrary/libs
folder to see if AR was properly exported. It should contain files similar toUnityARCore.aar
,ARPresto.aar
,arcore_client.aar
andunityandroidpermissions.aar
.If your setup and export was done correctly, your project should automatically load these files.
If it doesn't, check if yourandroid/build.gradle
file contains theflatDir
section added in the android setup step 7.If your
XR Plugin Management
plugin is version 4.4 or higher, Unity also exports the xrmanifest.androidlib folder.Make sure to include it by adding the following line toandroid/settings.gradle
// settings.gradleinclude ":unityLibrary:xrmanifest.androidlib"// settings.gradle.kts (Flutter 3.29+)include(":unityLibrary:xrmanifest.androidlib")
With some Unity versions AR might crash at runtine with an error like:
java.lang.NoSuchFieldError: no "Ljava/lang/Object;" field "mUnityPlayer" in class
.
See the Android setup step 3 on how to edit your MainActivity to fix this.
ℹ️AR Foundation iOS
- Open theios/Runner/Info.plist and add a camera usage description.
For example:
<dict>+ <key>NSCameraUsageDescription</key>+ <string>$(PRODUCT_NAME) uses Cameras</string> </dict>
ℹ️Vuforia Android
Your export should contain a Vuforia library in the
android/unityLibrary/libs/
folder. Currently namedVuforiaEngine.aar
.If your setup and export was done correctly, your project should automatically load this file.
If it doesn't, check if yourandroid/build.gradle
file contains theflatDir
section added in the android setup step 7.
In case this gets outdated or broken, check theVuforia documentation
ℹ️Vuforia iOS
These steps are based on theseVuforia docs andthis comment
- Open theios/Runner/Info.plist and add a camera usage description.
For example:
<dict>+ <key>NSCameraUsageDescription</key>+ <string>$(PRODUCT_NAME) uses Cameras</string> </dict>
In Xcode,Select
Runner
>General
tab.
InFrameworks, Libraries, and Embedded content
add the Vuforia frameworks. This is where you addedUnityFramework.framework in step 4 of the iOS setup.You should be able to find them in
/ios/UnityLibrary/Frameworks/com.ptc.vuforia.engine/Vuforia/Plugins/iOS/
.
Currently these areVuforia.framework
UnityDriver.framework
To support Vuforia target databases, move the
Unity-iPhone/Vuforia
folder from Unity-iPhone to Runner. Then setTarget Membership
of this folder to Runner.Make sure pods are installed after your Unity export, either using
flutter run
or by runningpod install
in the ios folder.
We recommend using a physical iOS or Android device, as emulator support is limited.
Below are the limited options to use an emulator.
ℹ️iOS Simulators
TheTarget SDK
option in the Unity player settings is important here.
Device SDK
exports an ARM build. (Which doesNOT work on ARM simulators)Simulator SDK
exports and x86 build for simulators.
If you use ARKit or ARFoundation you are out of luck, iOS simulators do NOT support ARKit.
The rest depends on the type of processor in your mac:
- Export from Unity using
Device SDK
as target. - In Xcode, go to the General tab of Runner.
- In Supported destinations add
Mac (Designed for iPhone)
orMac (Designed for iPad)
. - Now select this as the target device to run on.
- You can now run the app directly on your mac instead of a simulator.
Set
Simulator SDK
in the Unity player settings.Make sure there are no AR or XR packages included in the Unity package manager.
(You will get the errorsymbol not found in flat namespace '_UnityARKitXRPlugin_PluginLoad
otherwise)(Apple Silicon) Get Xcode to use a Rosetta emulator.
The next step assumes Xcode 14.3 or newer, if you use an older version look up how to start Xcode using Rosetta instead.
- In Xcode go to
Product -> Destination -> Destination Architectures
and make sure Rosetta destinations are visible.
- Now you need to check the architecture settings in Xcode.
- Select
Unity-iPhone
and go toBuild settings
->Architectures
.
If you exported Unity with the Simulator SDK, it should show onlyx86_64
for architectures. - Now select
Runner
and change the architecture to exactly match Unity-iPhone.
Make surex86_64
is the only entry, not one of multiple. - Now select
Pods
and clickflutter_unity_widget
in targets.
Go to Architectures in build settings again and setBuild Active Architecture Only
toYES
.
(We want this to only use the active x86_64, not fall back to arm.) - Run
Product -> Clean Build Folder
to make sure the new architecture settings are used. - Now you should be able to launch Runner on a Simulator using Rosetta.
On Xcode 14.3 or higher the simulator should have(Rosetta)
in the name. - Depending on your Flutter plugins, you might have to change the architecture for other installed Pods as well.
ℹ️Android emulators
Unity only supports ARM build targets for Android. However most Android emulators are x86 which means they simply won't work.
Computer with ARM processor
If your computer has an ARM processor (e.g. Apple Silicon, Qualcomm) you should be able to emulate Android without issue.
Create a virtual device using Android studio and make sure that the system image has an ABI that includes 'arm'.On macs with Apple Silicon (M1, M2), ARM emulators should be the default install option.
This was tested on Mac, but not on Linux or Windows.
Computer with x86/x64 processor
If you computer does not have an ARM processor, like most computers running on Intel or AMD, your options are limited.You have 2 options:
- Download an ARM emulator from Android Studio anyway.
While adding a virtual device in android studio, on the 'System image' screen, select 'other images' and make sure to use and ABI that includes 'arm'.
The emulator will likely crash immediately or run extremely slow.
This is not recommended. - Use the Chrome OS architecture
This is not officialy supported by Unity and there is no guarantee that it will work, but the Chrome OS target does seem to work on x86 Android emulators.
Expect (visual) glitches and bugs- Enable
x86 (Chrome OS)
andx86-64 (Chrome OS)
in the Unity player settings before making an export.
You might now be able to run on an regular Android emulator. - Disable these settings again if you want to publish your app.
- Enable
- Download an ARM emulator from Android Studio anyway.
On a
UnityWidget
widget, get theUnityWidgetController
received by theonUnityCreated
callback.Use the method
postMessage
to send a string, using the GameObject name and the name of a behaviour method that should be called.
// Snippet of postMessage usage in the example project._unityWidgetController?.postMessage('Cube',// GameObject name'SetRotationSpeed',// Function name in attached C# script speed,// Function parameter (string));
Select the GameObject that should execute the communication and go toInspector > Add Component > Unity Message Manager.
Create a new
MonoBehaviour
subclass and add to the same GameObject as a script.On this new behaviour, call
GetComponent<UnityMessageManager>()
to get aUnityMessageManager
.Use the method
SendMessageToFlutter
to send a string. Receive this message using theonUnityMessage
callback of aUnityWidget
.
// Send a basic string to FlutterSendMessageToFlutter("Hello there!");
// If you want to send multiple parameters or objects, use a JSON string.// This is a random object serialized to JSON using Json.net.JObjecto=JObject.FromObject(new{id=1,name="Object 1",whatever=12});SendMessageToFlutter(o.ToString());
import'package:flutter/material.dart';import'package:flutter_unity_widget/flutter_unity_widget.dart';voidmain() {runApp(constMaterialApp( home:UnityDemoScreen(), ), );}classUnityDemoScreenextendsStatefulWidget {constUnityDemoScreen({Key? key}):super(key: key);@overrideState<UnityDemoScreen>createState()=>_UnityDemoScreenState();}class_UnityDemoScreenStateextendsState<UnityDemoScreen> {UnityWidgetController? _unityWidgetController;@overrideWidgetbuild(BuildContext context) {returnScaffold( body:Container( color:Colors.yellow, child:UnityWidget( onUnityCreated: onUnityCreated, ), ), ); }// Callback that connects the created controller to the unity controllervoidonUnityCreated(UnityWidgetController controller) { _unityWidgetController= controller; }}
import'package:flutter/material.dart';import'package:flutter_unity_widget/flutter_unity_widget.dart';voidmain() {runApp(constMaterialApp( home:UnityDemoScreen(), ), );}classUnityDemoScreenextendsStatefulWidget {constUnityDemoScreen({Key? key}):super(key: key);@overrideState<UnityDemoScreen>createState()=>_UnityDemoScreenState();}class_UnityDemoScreenStateextendsState<UnityDemoScreen> {UnityWidgetController? _unityWidgetController;double _sliderValue=0.0;@overrideWidgetbuild(BuildContext context) {returnScaffold( appBar:AppBar( title:constText('Unity Flutter Demo'), ), body:Stack( children:<Widget>[UnityWidget( onUnityCreated: onUnityCreated, onUnityMessage: onUnityMessage, onUnitySceneLoaded: onUnitySceneLoaded, ),// Flutter UI Stacked on top of Unity to demo Flutter -> Unity interactions.// On web this requires a PointerInterceptor widget.Positioned( bottom:0,// <You need a PointerInterceptor here on web> child:SafeArea( child:Card( elevation:10, child:Column( children:<Widget>[constPadding( padding:EdgeInsets.only(top:20), child:Text("Rotation speed:"), ),Slider( onChanged: (value) {setState(() { _sliderValue= value; });// Send value to UnitysetRotationSpeed(value.toString()); }, value: _sliderValue, min:0.0, max:1.0, ), ], ), ), ), ), ], ), ); }// Communcation from Flutter to UnityvoidsetRotationSpeed(String speed) { _unityWidgetController?.postMessage('Cube','SetRotationSpeed', speed, ); }// Callback that connects the created controller to the unity controllervoidonUnityCreated(UnityWidgetController controller) { _unityWidgetController= controller; }// Communication from Unity to FluttervoidonUnityMessage(dynamic message) {print('Received message from unity: ${message.toString()}'); }// Communication from Unity when new scene is loaded to FluttervoidonUnitySceneLoaded(SceneLoaded? sceneInfo) {if (sceneInfo!=null) {print('Received scene loaded from unity: ${sceneInfo.name}');print('Received scene loaded from unity buildIndex: ${sceneInfo.buildIndex}'); } }}
fullscreen
(Enable or disable fullscreen mode on Android)
pause()
(Use this to pause unity player)resume()
(Use this to resume unity player)unload()
(Use this to unload unity player) *Requires Unity 2019.4.3 or laterquit()
(Use this to quit unity player)postMessage(String gameObject, methodName, message)
(Allows you invoke commands in Unity from flutter)onUnityMessage(data)
(Unity to flutter binding and listener)onUnityUnloaded()
(Unity to flutter listener when unity is unloaded)onUnitySceneLoaded(String name, int buildIndex, bool isLoaded, bool isValid,)
(Unity to flutter binding and listener when new scene is loaded)
Location: Unity
Error:
Multiple precompiled assemblies with the same name Newtonsoft.Json.dll included on the current platform. Only one assembly with the same name is allowed per platform. (Assets/FlutterUnityIntegration/JsonDotNet/Assemblies/AOT/Newtonsoft.Json.dll)PrecompiledAssemblyException: Multiple precompiled assemblies with the same name Newtonsoft.Json.dll included on the current platform. Only one assembly with the same name is allowed per platform.
Solution:Locate the listed dll file, in this case:Assets/FlutterUnityIntegration/JsonDotNet/Assemblies/AOT/Newtonsoft.Json.dll
- Option 1:Delete the dll file or rename the file extension (e.g.
.dll.txt
) to stop it from being imported. - Option 2:Uninstall the package that conflicts in the Unity package manager (usually Version control, or Collab).The exact package can be found by looking for newtonsoft in
package-lock.json
Location: Unity
Error:
The type or namespace name 'Newtonsoft' could not be found (are you missing a using directive or an assembly reference?)The type or namespace name 'JObject' could not be found (are you missing a using directive or an assembly reference?)The type or namespace name 'JToken' could not be found (are you missing a using directive or an assembly reference?)The type or namespace name 'JToken' could not be found (are you missing a using directive or an assembly reference?)
Solution:
Include the Newtonsoft JsonDotNet library.It is likely already included in your project with a wrong file extension:Assets/FlutterUnityIntegration/JsonDotNet/Assemblies/AOT/Newtonsoft.Json.dll.txt
Rename the.dll.txt
extension to.dll
in your file explorer and open Unity again.
Alternatively you can manually addthe library from the Unity package manager.
Location: Unity
Error:
InvalidOperationException: The build target does not support build appending.
Solution:
- Open theunity/project-name/Assets/FlutterUnityIntegration/Editor/Build.cs file.
1.1. On line 48, change the following:
- var options = BuildOptions.AcceptExternalModificationsToPlayer;+ var options = BuildOptions.AllowDebugging;+ EditorUserBuildSettings.exportAsGoogleAndroidProject = true;
1.2. On line 115, change the following:
- var options = BuildOptions.AcceptExternalModificationsToPlayer;+ var options = BuildOptions.AllowDebugging;
Location: Android Studio
Error:
minSdkVersion XX cannot be smaller than version 19 declared in library \ [:flutter_unity_widget] .../AndroidManifest.xml as the library might be using \ APIs not available in XX
Solution:
- Open theandroid/app/build.gradle file and change the following:
- minSdkVersion XX+ minSdkVersion 19
Location: Android Studio
Error:
e: .../FlutterUnityWidgetBuilder.kt: (15, 42): Expecting a parameter declaratione: .../FlutterUnityWidgetBuilder.kt: (23, 25): Expecting an argumente: .../FlutterUnityWidgetController.kt: (22, 44): Expecting a parameter declaratione: .../FlutterUnityWidgetFactory.kt: (13, 58): Expecting a parameter declaration
Solution:
- Open theandroid/build.gradle file and change the following:
- ext.kotlin_version = '1.3.50'+ ext.kotlin_version = '1.4.31'
Location: Android Studio
Error:
Unable to find a matching variant of project :unityLibrary:
Solution:
- Open theandroid/app/build.gradle file and change the following:
lintOptions { disable 'InvalidPackage'+ checkReleaseBuilds false }
The easiest way to apply flavors for your app would be:flutter_flavorizr.
If you use flavors in your app you will notice that especially iOS crashes while running or building your app!Here are the necessary steps for flavored apps:
No changes needed. Flavors are applied without any additional setups.
For your Unity iOS-Build you have to add your flavors to your Unity iOS Configuration.
- Check your actual
Runner
(your app) configurations. If you have for example the flavors:
- dev
- prod
YourRunner
configurations are looking like this:
So you have the flavors:
Debug-dev
Profile-dev
Release-dev
Debug-prod
Profile-prod
Release-prod
These flavors needs to be added to yourUnity-IPhone
project.
- Go into your
Unity-IPhone
project -> PROJECTUnity-IPhone
-> Info:
Here you can see in the Configurations section only:
Release
ReleaseForProfiling
ReleaseForRunning
Debug
- Copy
Debug
configuration twice and rename them toDebug-dev
and the second toDebug-prod
.
You can do that by selecting+
and duplicate the configuration like this:
Repeat this with
Release
toRelease-dev
andRelease-prod
.Repeat this with
Release
toProfile-dev
andProfile-prod
.Your
Unity-IPhone
configurations should now look like this:
Flutter on default doesn't support--flavor
for building web. But you can set your targetmain.dart
entrypoint (with-t main.dart
) while running and building. So if you setup your flavors properly there're also no changes needed for web to apply changes for your Flutter-Unity web App.
- Remember to disabled fullscreen in unity player settings to disable unity fullscreen.
- Unity freezes and crashes on Android, please use OpenGL3 as Graphics API.
- Project fails to build due to some native dependencies in your unity project, please integrate the native libraries for those dependencies on Android or iOS
- App crashes on screen exit and re-entry do this
Build Setting - iOS - Other Settings - Configuration - Enable Custom Background Behaviors or iOS
- Android builds takes forever to complete Unity 2022.1.*, remove these lines from unityLibrary/build.gradle file
commandLineArgs.add("--enable-debugger")commandLineArgs.add("--profiler-report")commandLineArgs.add("--profiler-output-file=" + workingDir + "/build/il2cpp_"+ abi + "_" + configuration + "/il2cpp_conv.traceevents")
Flutter widgets stacked on top of the UnityWidget will not register clicks or taps. This is aFlutter issue and can be solved by using thePointerInterceptor package.
Example usage:
Stack( children: [UnityWidget( onUnityCreated: onUnityCreated, onUnityMessage: onUnityMessage, onUnitySceneLoaded: onUnitySceneLoaded, ),Positioned( bottom:20, left:20, right:20, child:PointerInterceptor( child:ElevatedButton( onPressed: () {// do something }, child:constText('Example button'), ), ), ),
We already integrated this into ourExamples in the/example
folder.
Support this project with your organization. Your donations will be used to help children first and then those in need. Your logo will show up here with a link to your website. [Contribute]
Thanks goes to these wonderful people (emoji key):
Rex Raphael 💻📖💬🐛👀✅ | Thomas Stockx 💻📖💬✅ | Kris Pypen 💻📖💬✅ | Lorant Csonka 📖📹 |
This project follows theall-contributors specification. Contributions of any kind welcome!
About
Embeddable unity game engine view for Flutter. Advance demo herehttps://github.com/juicycleff/flutter-unity-arkit-demo
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.