Created
October 24, 2023 04:13
-
-
Save tracer8/6ac9ace808beaff9d1c0421c4bbbee9a to your computer and use it in GitHub Desktop.
Unity 2020 change gradle version
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
public class AutoChangeGradleVersion : IPostGenerateGradleAndroidProject, IPreprocessBuildWithReport | |
{ | |
public int callbackOrder | |
{ | |
get | |
{ | |
return 1; | |
} | |
} | |
public void OnPreprocessBuild(BuildReport report) | |
{ | |
SetGradleDistributionUrlTo72(); | |
} | |
public static void SetGradleDistributionUrlTo72() | |
{ | |
// Get the path to the gradle-wrapper.properties file. | |
string gradleWrapperPropertiesPath = Path.Combine(Application.dataPath, "../Temp/gradleOut/gradle/wrapper/gradle-wrapper.properties"); | |
// Check if the file exists. | |
if (!File.Exists(gradleWrapperPropertiesPath)) | |
{ | |
Debug.LogWarning("The gradle-wrapper.properties file does not exist."); | |
return; | |
} | |
// Read the contents of the file. | |
string gradleWrapperPropertiesContents = File.ReadAllText(gradleWrapperPropertiesPath); | |
// Replace the old distribution URL with the new one. | |
gradleWrapperPropertiesContents = gradleWrapperPropertiesContents.Replace("gradle-6.1.1-all.zip", "gradle-7.2-all.zip"); | |
// Write the updated contents back to the file. | |
File.WriteAllText(gradleWrapperPropertiesPath, gradleWrapperPropertiesContents); | |
// Debug log a message to confirm that the operation was successful. | |
Debug.Log("The Gradle distribution URL has been successfully updated to 7.2."); | |
} | |
public void OnPostGenerateGradleAndroidProject(string path) | |
{ | |
SetGradleDistributionUrlTo72(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment