Skip to content

[Android] Fix duplicate and missing namespace in UnityLibrary build.gradle. #36

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 22, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,28 @@ protected override void TransformExportedProject(string exportPath)
return;
}
string buildGradleContents = File.ReadAllText(buildGradleFile.FullName);
Regex regexAndroidBlock = new Regex(Regex.Escape("android {"));
buildGradleContents = regexAndroidBlock.Replace(buildGradleContents, "android {\n\tnamespace 'com.unity3d.player'", 1);
File.WriteAllText(buildGradleFile.FullName, buildGradleContents);
Debug.Log($"Added namespace 'com.unity3d.player' to {buildGradleFile.FullName} for Gradle 8 compatibility");
// some unity versions might already include it
if(!buildGradleContents.Contains("namespace")) {
Regex regexAndroidBlock = new Regex(Regex.Escape("android {"));
buildGradleContents = regexAndroidBlock.Replace(buildGradleContents, "android {\n\tnamespace 'com.unity3d.player'", 1);
File.WriteAllText(buildGradleFile.FullName, buildGradleContents);
Debug.Log($"Added namespace 'com.unity3d.player' to {buildGradleFile.FullName} for Gradle 8 compatibility");
}

// (optional) Add the namespace 'com.UnityTechnologies.XR.Manifest' to unityLibrary\xrmanifest.androidlib\build.gradle
// for compatibility with Gradle 8
FileInfo xrBuildGradleFile = new FileInfo(Path.Combine(exportPath, "xrmanifest.androidlib", "build.gradle"));
if(xrBuildGradleFile.Exists) {
string xrBuildGradleContents = File.ReadAllText(xrBuildGradleFile.FullName);
// some unity versions might already include it
if(!xrBuildGradleContents.Contains("namespace")) {
Regex regexAndroidBlock = new Regex(Regex.Escape("android {"));
xrBuildGradleContents = regexAndroidBlock.Replace(xrBuildGradleContents, "android {\n\tnamespace 'com.UnityTechnologies.XR.Manifest'", 1);
File.WriteAllText(xrBuildGradleFile.FullName, xrBuildGradleContents);
Debug.Log($"Added namespace 'com.UnityTechnologies.XR.Manifest' to {xrBuildGradleFile.FullName} for Gradle 8 compatibility");
}
}


DirectoryInfo burstDebugInformation = new DirectoryInfo(Path.Join(exportPath, "..", "unityLibrary_BurstDebugInformation_DoNotShip"));
if(burstDebugInformation.Exists) {
Expand Down