Created
September 21, 2022 15:35
-
-
Save gilzoide/9d970b4f6cac0c9773e1ebb5271a0b7c to your computer and use it in GitHub Desktop.
Unity Gradle Android plugin version setter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#if UNITY_ANDROID | |
using System.IO; | |
using System.Text.RegularExpressions; | |
using UnityEditor.Android; | |
public class GradleAndroidPluginVersionSetter : IPostGenerateGradleAndroidProject | |
{ | |
public const string GradleAndroidPluginVersion = "3.4.3"; | |
public int callbackOrder => 0; | |
public void OnPostGenerateGradleAndroidProject(string path) | |
{ | |
#if UNITY_2019_1_OR_NEWER | |
// Use project's root folder instead of /unityLibrary | |
path = Path.GetDirectoryName(path); | |
#endif | |
SetupGradleAndroidPlugin(path, GradleAndroidPluginVersion); | |
} | |
public static void SetupGradleAndroidPlugin(string path, string androidPluginVersion) | |
{ | |
string buildScript = File.ReadAllText(Path.Combine(path, "build.gradle")); | |
buildScript = Regex.Replace(buildScript, @"(?<=classpath\s'com.android.tools.build:gradle:)[^']+", androidPluginVersion); | |
File.WriteAllText(Path.Combine(path, "build.gradle"), buildScript); | |
} | |
} | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment