Skip to content

[Flutter 3.29] UnityLibrary Build Fails in New Flutter Projects Using Gradle Kotlin DSL (build.gradle.kts) #1002

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

Closed
suryanadiminti99 opened this issue Feb 18, 2025 · 5 comments

Comments

@suryanadiminti99
Copy link

Description:
In newly created Flutter projects, Flutter now generates only build.gradle.kts (Gradle Kotlin DSL) files instead of traditional build.gradle (Groovy). When trying to build unityLibrary, the build fails because it does not recognize build.gradle.

I'm facing a compilation issue when using flutter_unity_widget in my Flutter project, which uses Gradle Kotlin DSL (build.gradle.kts). The error occurs when running ./gradlew assembleDebug or flutter build.

Error Log
Execution failed for task ':flutter_unity_widget:compileReleaseKotlin'.

A failure occurred while executing org.jetbrains.kotlin.compilerRunner.GradleCompilerRunnerWithWorkers$GradleKotlinCompilerWorkAction
Compilation error. See log for more details

Kotlin Version
kotlin -version
Kotlin version 2.1.10-release-473 (JRE 17.0.14+0)

Steps to Reproduce:
Create a Flutter project with Gradle Kotlin DSL (build.gradle.kts).
Add flutter_unity_widget as a dependency.
Run flutter pub get.
Attempt to build the project with flutter build apk or ./gradlew assembleDebug.

@suryanadiminti99
Copy link
Author

@juicycleff Hi Hope you are doing well, I am trying this solution from the last 5 days. I am unable to find the solution. Even I tried with your experimental link.

[](#966)

I got this error after running the flutter project.

Image

@suryanadiminti99
Copy link
Author

Image

@suryanadiminti99
Copy link
Author

@juicycleff In your plugin
dependencies {
implementation project(':unityLibrary')
implementation(name: 'unity-classes', ext:'jar')

implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation "androidx.lifecycle:lifecycle-common:$lifecycle_version"
implementation "androidx.lifecycle:lifecycle-common-java8:$lifecycle_version"
implementation "androidx.lifecycle:lifecycle-process:$lifecycle_version"
implementation "androidx.annotation:annotation:$annotation_version"

compileOnly rootProject.findProject(":flutter_plugin_android_lifecycle")

// FOR DEV ONLY

// implementation(name: 'flutter', ext:'jar')
}

Error in flutter build apk

  • Doesn't say anything about org.gradle.plugin.api-version (required '8.2.1')
    - Variant 'testResultsElementsForTest' capability dev.flutter.plugin:gradle:1.0.0:
    - Incompatible because this component declares a component of category 'verification' and the consumer needed a library
    - Other compatible attributes:
    - Doesn't say anything about how its dependencies are found (required its dependencies declared externally)
    - Doesn't say anything about its target Java version (required compatibility with Java 8)
    - Doesn't say anything about its elements (required them packaged as a jar)
    - Doesn't say anything about org.gradle.plugin.api-version (required '8.2.1')
    - Doesn't say anything about its usage (required runtime)

@timbotimbo
Copy link
Collaborator

I just updated the master branch with some Kotlin DSL fixes.

I updated the readme with the new syntax, and the Unity export script now handles .gradle.kts files.

With those I managed to build and run the plugin in a new Flutter 3.29 project.
The gradle setup of the example is still outdated, so if you want to use the example, copy the lib folder into a new project.

As this is on the master branch and not pub.dev:

For Flutter: you can either download the plugin and include it using a relative path

flutter_unity_widget:
    path: <folder path>

or include it using the git url.

flutter_unity_widget:
    git:
      url: https://github.com/juicycleff/flutter-unity-view-widget.git
      ref: master # branch name

For Unity:
Make sure to use example\unity\DemoApp\assets\Flutter\FlutterUnityIntegration\Edior\Build.cs from the master branch. As that fixes the Unity export for .gradle.kts files.

@timbotimbo timbotimbo changed the title UnityLibrary Build Fails in New Flutter Projects Using Gradle Kotlin DSL (build.gradle.kts) [Flutter 3.29] UnityLibrary Build Fails in New Flutter Projects Using Gradle Kotlin DSL (build.gradle.kts) Feb 23, 2025
@suryanadiminti99
Copy link
Author

Thanks a lot for your help, @timbotimbo . Your solution resolved my Flutter KTS issue, which I had been troubleshooting for the past five days. Now, I can successfully generate both Android and iOS builds without any blockers. Really appreciate your detailed explanation and guidance!

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

2 participants