quickstart-unity
quickstart-unity copied to clipboard
[Bug] Gradle build fails on Unity 2021 when custom gradle templates are enabled
[REQUIRED] Please fill in the following fields:
- Unity editor version: 2021.2.6f1
- Firebase Unity SDK version: 8.6.2
- Source you installed the SDK: .unitypackage
- Problematic Firebase Component: Analytics
- Other Firebase Components in use: None
- Additional SDKs you are using: Facebook, None
- Platform you are using the Unity editor on: Mac
- Platform you are targeting: Android
- Scripting Runtime: IL2CPP
[REQUIRED] Please describe the issue here:
My APK fails during building gradle with following error:
CommandInvokationFailure: Gradle build failed. /Applications/Unity/Hub/Editor/2021.2.6f1/PlaybackEngines/AndroidPlayer/OpenJDK/bin/java -classpath "/Applications/Unity/Hub/Editor/2021.2.6f1/PlaybackEngines/AndroidPlayer/Tools/gradle/lib/gradle-launcher-6.1.1.jar" org.gradle.launcher.GradleMain "-Dorg.gradle.jvmargs=-Xmx4096m" "assembleRelease"
stderr[ Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF-8
FAILURE: Build failed with an exception.
- What went wrong: Could not determine the dependencies of task ':unityLibrary:compileReleaseAidl'.
Could not resolve all task dependencies for configuration ':unityLibrary:releaseCompileClasspath'. Could not find com.google.firebase:firebase-analytics-unity:8.6.2. Required by: project :unityLibrary Could not find com.google.firebase:firebase-app-unity:8.6.2. Required by: project :unityLibrary
Steps to reproduce:
Have you been able to reproduce this issue with just the Firebase Unity quickstarts (this GitHub project)? What's the issue repro rate?
Yes, 100% when I enable mainTemplate.gradle and disable Auto Resolution in Android Resolver Settings.
What happened? How can we make the problem occur?
- Run Analaytics Quick start in Unity 2021.2.6f1.
- Enable mainTemplate.gradle, launcherTemplate.gradle, baseProjectTemplate.gradle and gradleTemplate.properties
- Build APK.
It builds fine If I don't enable gradle scripts and enable Auto Resolution. It is also building without any problem on older Unity versions with custom gradle files.
Hi @kashif789us,
Thanks for reporting this issue. I was also able to replicate this issue using the quickstart with the same Unity version. Here is the error message I got for reference:

I'll be marking this as a bug for now. Let me discuss this with the team, and we'll get back to you once we have updates.
Unity editor version: 2021.2.0f1 Firebase Unity SDK version: 8.7.0 Source you installed the SDK: .unitypackage Problematic Firebase Component: Analytics / App / Auth / Crashlytics / Database / Firestore / Storage Additional SDKs you are using: Error is replicated in an empty project with only Firebase Platform you are using the Unity editor on: PC Platform you are targeting: Android Scripting Runtime: IL2CPP
Hello, I am getting the same issues on a slightly different editor and Firebase version. The build breaks with the Custom Main Gradle Template enabled. In the Gradle file every dependency that has "-unity" causes it to fail during build. I was able to comment them out 1 by 1 and build successfully, but that's not the point.
Sample failure message: FAILURE: Build failed with an exception.
- What went wrong: Could not determine the dependencies of task ':launcher:lintVitalRelease'.
Could not resolve all artifacts for configuration ':launcher:debugRuntimeClasspath'. Could not find com.google.firebase:firebase-app-unity:8.7.0. Searched in the following locations: -
Hi all,
Thanks to @deetmo, this appears to be a regression from the Unity side.
https://issuetracker.unity3d.com/issues/android-template-variable-star-star-dir-unityproject-star-star-is-not-properly-substituted-when-exporting-a-gradle-project?_ga=2.122711496.294034660.1640030138-1623586750.1636598340
Their fix has been integrated to 2022.1.0a13
but it is still in-review for 2021.2
.
If you are experiencing this issue, here are some workarounds
- Downgrade Unity to
2021.1
- Use the workaround @deetmo provided here. https://github.com/googlesamples/unity-jar-resolver/issues/478#issuecomment-980615877
It would be rather challenging to provide a patch for this in EDm4U but we'll see what we can do.
Problem Fixed here : https://www.codeprofessionally.com/2022/03/gradle-build-failed-unity.html
i can fix this error send message on facebook : https://www.facebook.com/Code-Prof-110511874050372
Hi, all
can anyone suggest to me a solution for the same?
Still relevant for Unity 2022 and 2023. I managed to make it work on 2021, but not on the latest ones. I've spent 4 days already on it and became a master in gradle files configuration, but still can not fix it. Any help?
Problem Fixed here : https://www.codeprofessionally.com/2022/03/gradle-build-failed-unity.html
@CodeProf14 I tried that also, but it still doesn't work!
Let me know if u find any solution
Same here after trying to upgrade to Unity 2022
If you are still having this issue and can't update Unity, place this script into an Editor folder:
using System.IO;
using UnityEditor;
using UnityEditor.Build;
using UnityEditor.Build.Reporting;
using UnityEngine;
/// <summary>
/// Fix for https://issuetracker.unity3d.com/issues/android-template-variable-star-star-dir-unityproject-star-star-is-not-properly-substituted-when-exporting-a-gradle-project
/// This bug is fixed in Unity 2021.2.8. This script can be removed when updating Unity.
/// </summary>
class FixGradleTemplateBug : IPreprocessBuildWithReport, IPostprocessBuildWithReport
{
public int callbackOrder { get { return 0; } }
private const string GradleMainTemplatePath = "Assets/Plugins/Android/mainTemplate.gradle";
private string originalMainTemplateContents = null;
public void OnPreprocessBuild(BuildReport report)
{
originalMainTemplateContents = null;
if (File.Exists(GradleMainTemplatePath))
{
originalMainTemplateContents = File.ReadAllText(GradleMainTemplatePath);
string projectDir = Path.GetDirectoryName(Application.dataPath);
Debug.Log($"To fix a bug, replacing **DIR_UNITYPROJECT** with \"{projectDir}\" in the gradle template file \"{GradleMainTemplatePath}\"."
+ " This fix can be removed after updating to Unity 2021.2.8 or later");
string fixedContents = originalMainTemplateContents.Replace("**DIR_UNITYPROJECT**", projectDir);
File.WriteAllText(GradleMainTemplatePath, fixedContents);
}
}
public void OnPostprocessBuild(BuildReport report)
{
if (!string.IsNullOrEmpty(originalMainTemplateContents))
{
File.WriteAllText(GradleMainTemplatePath, originalMainTemplateContents);
originalMainTemplateContents = null;
}
}
}
Same here after migration from 2021.3.16 to 2022.3.2
I encountered a similar issue with Unity Editor version 2021.3.9f1 and all other 2021 Unity versions while building the APK. However, after some troubleshooting, I found a workaround that might be helpful to others facing the same problem.
Solution:
- Unity Version: I experienced the issue with Unity LTS version 2021.3.9f1 and other 2021 versions.
- Successful Build: After switching to Unity LTS version 2022.3.9f1, the build process worked without any problems.
I hope this information is helpful for others facing the same problem. Please let me know if you need any further details.
I got error while build in Unity android port (and two more similar errors for files: firebase-messaging-unity-11.6.0.pom and google-signin-support-1.0.4.pom):
Could not determine the dependencies of task ':launcher:lintVitalRelease'.
Could not resolve all artifacts for configuration ':launcher:debugRuntimeClasspath'. Could not find com.google.firebase:firebase-app-unity:11.6.0. Searched in the following locations: - https://dl.google.com/dl/android/maven2/com/google/firebase/firebase-app-unity/11.6.0/firebase-app-unity-11.6.0.pom - https://repo.maven.apache.org/maven2/com/google/firebase/firebase-app-unity/11.6.0/firebase-app-unity-11.6.0.pom - https://artifactory.appodeal.com/appodeal-beta-public/com/google/firebase/firebase-app-unity/11.6.0/firebase-app-unity-11.6.0.pom - file:////Assets/GeneratedLocalRepo/Firebase/m2repository/com/google/firebase/firebase-app-unity/11.6.0/firebase-app-unity-11.6.0.pom - file:////Assets/GeneratedLocalRepo/GoogleSignIn/Editor/m2repository/com/google/firebase/firebase-app-unity/11.6.0/firebase-app-unity-11.6.0.pom - file:/C:/Users/Admin/.m2/repository/com/google/firebase/firebase-app-unity/11.6.0/firebase-app-unity-11.6.0.pom - file:/C:/Unity/projects/X/Library/Bee/Android/Prj/IL2CPP/Gradle/unityLibrary/libs/firebase-app-unity-11.6.0.jar - file:/C:/Unity/projects/X/Library/Bee/Android/Prj/IL2CPP/Gradle/unityLibrary/libs/firebase-app-unity.jar
But the problem is that I have these files! They are located along one of the paths from the search list. in the generated directory: c:\Unity\projects\X\Assets\GeneratedLocalRepo\Firebase\m2repository\com\google\firebase\firebase-app-unity\11.6.0\firebase-app-unity-11.6.0.pom
Why am I getting an error? What could be the reason?