7

Since I want to add Firebase to my Android Game I want to include Google Auth. But I have the following Problem. I need to add some Code to the build.gradle File but I cant find it in my Unity Project.

Here is the manual I found from Firebase : https://firebase.google.com/docs/auth/android/google-signin

I searched on all my Drives for build.gradle but found nothing. Can you tell me where I find it or what do I have to do to implement the Code from the Link?

Programmer
  • 121,791
  • 22
  • 236
  • 328
Rene Ungerer
  • 115
  • 1
  • 3
  • 8

2 Answers2

10

From Unity v2018.3 onwards, you can add your own custom Gradle build file by simply enabling the Custom Gradle Template property on the Player window (which can be accessed by File > Build Settings > Player Settings > Publishing settings). This generates a default mainTemplate.gradle file for you, which you can edit.

It will be in the location: Assets/Plugins/Android/mainTemplate.gradle

Source: https://docs.unity3d.com/Manual/android-gradle-overview.html

Rohan Talesara
  • 186
  • 2
  • 6
  • I have an issue with this. Although the mainTemplate.gradle file in /Plugins/Android can be edited, whenever I want to build the project, Unity 2020.2.1f1 automatically resets the .gradle file to its previous state. What am I doing wrong? – CrazyBacon Jan 18 '21 at 13:17
  • @ CrazyBacon, you have to delete the commented line at the top of the file. That line makes the file reset on build. – emorphus Jul 13 '21 at 05:45
9

To use Gradle in Unity.

1.Go to <UnityInstallationDirecory>\Editor\Data\PlaybackEngines\AndroidPlayer\Tools\GradleTemplates, then copy mainTemplate.gradle file to your <ProjectName>Assets\Plugins\Android folder.

2.You can then modify mainTemplate.gradle to be whatever you want it to be. Now, to make sure the build uses the gradle file, change the Build System to "Gradle (New)".

enter image description here

Programmer
  • 121,791
  • 22
  • 236
  • 328