Reputation: 31
I am trying and failing to get crashlytics building in unity.
I am using unity 2018.4.30. It was added to unity as a package (7.0.2). Other firebase packages were already in the project and working. Initially I ran the dependency resolver and tried to build it. The resolver added these:
implementation 'com.google.firebase:firebase-crashlytics:17.2.2' //Packages/com.google.firebase.crashlytics/Firebase/Editor/CrashlyticsDependencies.xml:13
implementation 'com.google.firebase:firebase-crashlytics-unity:7.0.2' //Packages/com.google.firebase.crashlytics/Firebase/Editor/CrashlyticsDependencies.xml:20
which built but it crashed on launch with an error message pointing me to some android specific setup that had to be added to the gradle file (odd that the resolver didn't do it...)
I followed those instructions and added
classpath 'com.google.gms:google-services:4.3.5'
classpath 'com.google.firebase:firebase-crashlytics-gradle:2.5.0'
to dependencies
I also added
apply plugin: 'com.google.gms.google-services'
apply plugin: 'com.google.firebase.crashlytics'
to the gradle file
my gradle tools are:
classpath 'com.android.tools.build:gradle:3.4.3'
my error message is:
* What went wrong: A problem occurred configuring root project 'gradleOut'.
java.lang.ClassCastException: org.gradle.api.internal.file.DefaultFilePropertyFactory$DefaultDirectoryVar$1 cannot be cast to org.gradle.api.file.Directory
Upvotes: 2
Views: 1888
Reputation: 111
Update gradle wrapper to version 5.6.4 (from 5.4.1) solved my problem with this error.
gradle-wrapper.properties
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-all.zip
My Android Build Gradle tools is 3.5.4
com.android.tools.build:gradle:3.5.4
Upvotes: 4
Reputation: 31
the long and short of this is that my dependency resolver was not generating crashlytics_build_id.xml and a few other files. The error message led me to android specific gradle solution that weren't meant for unity clients. Once I undid my gradle changes and had those generated files everything was fine.
Upvotes: 0
Reputation: 3131
It's worth nothing that if you're using Unity, you should not have to edit gradle files at all. You can add a mainTemplate.gradle
file if you want for other reasons (I like doing this so EDM4U doesn't add a bunch of libraries to Assets/Plugins/Android
) but you have to be a little cautious (in newer versions of Unity, such as late 2019 and all of the 2020 branch you also have to add gradleTemplate.properties
).
You generally should only follow the Unity integration steps rather than the Android ones. The line apply plugin: 'com.google.gms.google-services'
actually conflicts with what the Firebase Unity plugin does. apply plugin: 'com.google.firebase.crashlytics'
can be made to work with some effort, but is also not necessary unless you're experimenting with NDK integration (this is an unsupported configuration in the Unity SDK and the native crash reporter doesn't currently work with Unity 2020 in my own testing).
I would recommend rolling back any build-config changes you've made to try to get Crashlytics working with Unity and try re-importing. It's also worth keeping the SDK as up to date as possible -- although looking at the release notes there shouldn't be any changes to Crashlytics between 7.0.2 and 7.1.0.
If the above doesn't work, there was an issue in the 6.x SDK branch with Unity 2020.1. You can try this workaround (note that I'm replacing everything with mainTemplate.gradle
since 2018 didn't split up projects like late 2019 and 2020):
Now open
mainTemplate.gradle
and look for something that looks roughly like:allprojects { buildscript { repositories {**ARTIFACTORYREPOSITORY** google() jcenter() } dependencies {
Inside
allprojects.buildscript.dependencies
(thedependencies {
bit in this example), add this code to tell gradle about Crashlytics:// Add the Crashlytics Gradle plugin. classpath 'com.google.firebase:firebase-crashlytics-gradle:2.2.0'
and this line of code to the very end of
mainTemplate.gradle
to add the Crashlytics plugin to your Application:// Apply the Crashlytics Gradle plugin apply plugin: 'com.google.firebase.crashlytics'
If Crashlytics is still broken, you can file a bug report. If the 2nd workaround works or you don't mind debugging your project in the public, you can file a GitHub issue here.
Upvotes: 0