[Bug] Android build fails if Kotlin files included in project
[REQUIRED] Please fill in the following fields:
- Unity editor version: 2021.3.29f1
- Firebase Unity SDK version: 11.4.0
- Source you installed the SDK: Unity Package Manager
- Problematic Firebase Component: Base App
- Other Firebase Components in use: NA
- Additional SDKs you are using: A single .kt file
- Platform you are using the Unity editor on: Mac
- Platform you are targeting: Android
- Scripting Runtime: IL2CPP
- Pre-built SDK from the website or open-source from this repo: pre-built
[REQUIRED] Please describe the issue here:
If any kotlin files are included in the Unity project the generated gradle project fails to build with incompatible Kotlin metadata issues.
Example project containing a single empty kotlin class attached:
Produces the following errors when built for Android:
e: /Users/allanbush/.gradle/caches/modules-2/files-2.1/androidx.annotation/annotation/1.5.0/857678d6b4ca7b28571ef7935c668bdb57e15027/annotation-1.5.0.jar!/META-INF/annotation.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.7.1, expected version is 1.4.2.
e: /Users/allanbush/.gradle/caches/transforms-2/files-2.1/3bace5d5f9a6e271a107a0b9ac931c14/jetified-kotlin-stdlib-1.7.10.jar!/META-INF/kotlin-stdlib.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.7.1, expected version is 1.4.2.
e: /Users/allanbush/.gradle/caches/transforms-2/files-2.1/7d85e3ac41f13fcbd1d0187ffb3f07f1/jetified-kotlin-stdlib-common-1.7.10.jar!/META-INF/kotlin-stdlib-common.kotlin_module: Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.7.1, expected version is 1.4.2.
Full log: Editor.log.zip
Removing either the NativeCode directory or the com.google.firebase.app entry from the package manifest resolves the issue and the build works as expected. But having both of these together results in the build failure.
This issue was not observed with version 9.6.0 of the firebase libraries.
Steps to reproduce:
- Unzip the attached project
- Replace the 0 byte files in the GooglePackages folder with the proper files: https://dl.google.com/games/registry/unity/com.google.firebase.app/com.google.firebase.app-11.4.0.tgz and https://dl.google.com/games/registry/unity/com.google.external-dependency-manager/com.google.external-dependency-manager-1.2.177.tgz
- Open the project, targeting an Android build
- Resolve the external dependencies: Assets->External Dependency Manager->Android Resolver->Resolve
- Build and run
Further investigation shows that this bug emerged with version 10.4 of the firebase libraries as version 10.3 works for me in the sample project.
The problem is mostly with dependencies. Some of the dependencies for Firebase seem to depend on Kotlin 1.7.1, but when a Kotlin file is included in Unity, it adds a dependency on Kotlin 1.4.2 in Unity 2021. If you use a custom mainTemplate.gradle file, you can adjust it to use a newer version of the Kotlin plugin, but that might also require changes to the gradle version being used.
From testing, another possibility is to update to Unity 2023. That seems to use Kotlin 1.7.2, which is compatible with the dependencies needed by Firebase. You might still need to set it to use a mainTemplate.gradle, since it might be confused between 1.7.1 and 1.7.2, but you don't actually need to change the file, just having it present is enough to resolve it.
Is there any chance for a LTS version of the Firebase Unity SDK that gets maintenance updates or work with LTS versions of Unity?
We only just found Unity 2022 stable enough to upgrade our project and Unity 2023 isn't scheduled to be "stable" until "late 2024". Having to run unsupported versions of the firebase libraries until than doesn't seem viable.
I've already run into an issue with phone authentication triggering a captcha because I can't register my app for the deprecated SafetyNet api and the 10.3 version of firebase auth doesn't support Play Integrity.
I was able to get this working by overriding the base gradle template and adding:
id 'org.jetbrains.kotlin.android' version '1.7.10' apply false
It's a little concerning making a change like this, but so far there doesn't appear to be any knock-ons with the rest of the project.