Skip to content

How to export Unity to a Flutter plugin #1000

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
laurentP22 opened this issue Feb 13, 2025 · 0 comments
Open

How to export Unity to a Flutter plugin #1000

laurentP22 opened this issue Feb 13, 2025 · 0 comments

Comments

@laurentP22
Copy link

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:

What I tried:

  • Created a new Flutter plugin named "bridge": flutter create --org com.example --template=plugin --platforms=android bridge
  • Added the DemoApp Unity project from the example app of this repository to the plugin (path: bridge/unity/DemoApp).
  • Opened the DemoApp project in Unity.
  • Executed Flutter -> Export Android Release.
    • The unityLibrary folder is correctly generated (path: bridge/android/unityLibrary).
  • Updated bridge/android/settings.gradle to convert the unityLibrary folder into a module:
rootProject.name = 'bridge'

include ":unityLibrary"
project(":unityLibrary").projectDir = file("./unityLibrary")
  • Updated bridge/android/build.gradle to add the directory to the repositories:
allprojects {
    repositories {
        flatDir {
            dirs "unityLibrary/libs"
        }

        google()
        mavenCentral()
    }
}
  • Updated bridge/android/build.gradle to 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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant