Skip to content

Commit

Permalink
in gradle worker UNITY_2022_3 part added
Browse files Browse the repository at this point in the history
  • Loading branch information
alihan98ersoy authored and Andronovo-bit committed Apr 4, 2024
1 parent 27d0a14 commit ab56694
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
10 changes: 6 additions & 4 deletions Assets/Huawei/Editor/Utils/HMSGradleFixer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,21 @@ public class HMSGradleFixer : IPostGenerateGradleAndroidProject
{
public int callbackOrder => 1;
private const string MINGRADLEVERSION = "3.5.4";
private const string agconnect_agcp = "classpath 'com.huawei.agconnect:agcp:1.9.1.301'";
//Unity 2022.3 and higher
private const string agconnect_agcp_7_2 = "classpath 'com.huawei.agconnect:agcp:1.9.1.301'";
//Unity 2019 and lower
private const string build_gradle = "classpath 'com.android.tools.build:gradle:" + MINGRADLEVERSION + "'";

private void GradleVersionFixer(string gradleFileAsString, string path)
{
#if UNITY_2022_2_OR_NEWER
#if UNITY_2022_3_OR_NEWER
// Grade 7.2
string currentBuildgradle = File.ReadAllText(Directory.GetParent(path).FullName + "/build.gradle").Replace("apply from: 'hmsBaseProjectTemplate.gradle'", "");

if (currentBuildgradle.Contains("dependencies")){
if(!currentBuildgradle.Contains("com.huawei.agconnect:agcp:")){

string buildscriptdependencies = "buildscript {\n\tdependencies {\n\t\t" + agconnect_agcp + "\n\t}\n}\n";
string buildscriptdependencies = "buildscript {\n\tdependencies {\n\t\t" + agconnect_agcp_7_2 + "\n\t}\n}\n";
currentBuildgradle = buildscriptdependencies + currentBuildgradle;
File.WriteAllText(Directory.GetParent(path).FullName + "/build.gradle", currentBuildgradle);
}
Expand All @@ -35,7 +37,7 @@ private void GradleVersionFixer(string gradleFileAsString, string path)
File.WriteAllText(Directory.GetParent(path).FullName + "/build.gradle", currentBuildgradle);
}
}else{
string buildscriptdependencies = "buildscript {\n\tdependencies {\n\t\t" + build_gradle + "\n\t\t" + agconnect_agcp + "\n\t}\n}\n";
string buildscriptdependencies = "buildscript {\n\tdependencies {\n\t\t" + build_gradle + "\n\t\t" + agconnect_agcp_7_2 + "\n\t}\n}\n";
currentBuildgradle = buildscriptdependencies + currentBuildgradle;
File.WriteAllText(Directory.GetParent(path).FullName + "/build.gradle", currentBuildgradle);
}
Expand Down
18 changes: 11 additions & 7 deletions Assets/Huawei/Editor/Utils/HMSGradleWorker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,14 @@ public HMSGradleWorker()

private void CreateGradleFiles(string[] gradleConfigs)
{
#if UNITY_2019_3_OR_NEWER
#if UNITY_2022_3_OR_NEWER
CreateMainGradleFile(gradleConfigs);
CreateLauncherGradleFile(gradleConfigs);
BaseProjectGradleFile("1.9.1.301");
#elif UNITY_2019_3_OR_NEWER
CreateMainGradleFile(gradleConfigs);
CreateLauncherGradleFile(gradleConfigs);
BaseProjectGradleFile();
BaseProjectGradleFile("1.6.1.300");

#elif UNITY_2018_1_OR_NEWER
CreateMainGradleFile(gradleConfigs);
Expand Down Expand Up @@ -118,7 +122,7 @@ private void CreateMainGradleFile(string[] gradleConfigs)
}
#endif
/* TODO:
#elif UNITY_2022_1_OR_NEWER
#elif UNITY_2022_1_OR_NEWER
//Gradle 7+ and classpath 'com.huawei.agconnect:agcp:1.9.1.301'
*/
}
Expand All @@ -130,15 +134,15 @@ private void CreateLauncherGradleFile(string[] gradleConfigs)
var stringBuilder = new StringBuilder();
stringBuilder.AppendLine("apply plugin: 'com.huawei.agconnect'\n");

#region Dependencies
#region Dependencies

stringBuilder.AppendLine("dependencies {");
for (int i = 0; i < gradleConfigs.Length; i++)
{
stringBuilder.AppendLine($"\t{AddDependency(gradleConfigs[i])}");
}
stringBuilder.AppendLine("}");
#endregion
#endregion
stringBuilder.AppendLine("android {");
stringBuilder.AppendLine("\tpackagingOptions {");
stringBuilder.AppendLine("\t\tpickFirst \"okhttp3/internal/publicsuffix/publicsuffixes.gz\"");
Expand All @@ -148,7 +152,7 @@ private void CreateLauncherGradleFile(string[] gradleConfigs)

File.WriteAllText(path, stringBuilder.ToString());
}
private void BaseProjectGradleFile()
private void BaseProjectGradleFile(string agcversion)
{
// Combine paths to get the full file path
string filePath = Path.Combine(Application.dataPath + "/Huawei/Plugins/Android/hmsBaseProjectTemplate.gradle");
Expand All @@ -169,7 +173,7 @@ private void BaseProjectGradleFile()
sb.AppendLine("\t\tdependencies {");

// Add the classpath dependency for Huawei's AGC
sb.AppendFormat("\t\t\t{0}\n", AddClasspath("com.huawei.agconnect:agcp:1.9.1.301"));
sb.AppendFormat("\t\t\t{0}\n", AddClasspath("com.huawei.agconnect:agcp:" + agcversion));

sb.AppendLine("\t\t}"); // End of dependencies
sb.AppendLine("\t}"); // End of buildscript
Expand Down

0 comments on commit ab56694

Please sign in to comment.