flutter-unity-view-widget
flutter-unity-view-widget copied to clipboard
How to export Unity to a Flutter plugin
Hi, I'm currently working on a Flutter app and would like to export Unity into an external Flutter plugin. The purpose of moving Unity integration to a separate plugin is to simplify our development process by:
- Having a specific example app to test the Unity integration independently.
- Reducing the number of files in the main app.
- Sharing the Unity code between multiple apps.
Until now, I've been focused on the Android integration. I've found two related topics on StackOverflow, but neither solution worked for me:
- Using Flutter Unity Widget and create a plugin with my Unity project
- How do I add library module dependency to a Flutter plugin’s Android folder correctly?
What I tried:
- Created a new Flutter plugin named "bridge":
flutter create --org com.example --template=plugin --platforms=android bridge - Added the
DemoAppUnity project from the example app of this repository to the plugin (path: bridge/unity/DemoApp). - Opened the
DemoAppproject in Unity. - Executed
Flutter -> Export Android Release.- The
unityLibraryfolder is correctly generated (path:bridge/android/unityLibrary).
- The
- Updated
bridge/android/settings.gradleto convert theunityLibraryfolder into a module:
rootProject.name = 'bridge'
include ":unityLibrary"
project(":unityLibrary").projectDir = file("./unityLibrary")
- Updated
bridge/android/build.gradleto add the directory to the repositories:
allprojects {
repositories {
flatDir {
dirs "unityLibrary/libs"
}
google()
mavenCentral()
}
}
- Updated
bridge/android/build.gradleto implement the module:
dependencies {
implementation project(':unityLibrary')
}
- When building the example app, it fails with:
FAILURE: Build failed with an exception.
* Where:
Build file '.../bridge/android/build.gradle' line: 76 // <-- Corresponds to `implementation project(':unityLibrary')`
* What went wrong:
A problem occurred evaluating project ':bridge'.
> Project with path ':unityLibrary' could not be found in project ':bridge'.
* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at https://help.gradle.org.
BUILD FAILED in 381ms
Error: Gradle task assembleDebug failed with exit code 1
I tried several configurations, but it always fails to build. I'm really not an expert in Android and Gradle configuration, so I might be missing something, or not configuring the project correctly. Or maybe it's actually not possible to do...
Has anyone successfully achieved such an integration?
Thanks for your assistance!