Skip to content
Merged
Show file tree
Hide file tree
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## Unreleased

### Fixes

- The SDK now ensures that the correct version of the Android SDK gets used during the build. This prevents dependency conflicts and no longer requires "clean" builds to resolve ([#2031](https://github.com/getsentry/sentry-unity/pull/2031))

## 3.0.1

### Fixes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,14 +228,16 @@ internal void CopyAndroidSdkToGradleProject(string unityProjectPath, string grad
throw new DirectoryNotFoundException($"Failed to find the Android SDK at '{androidSdkPath}'.");
}

Directory.CreateDirectory(targetPath);

_logger.LogInfo("Copying the Android SDK to '{0}'.", gradlePath);
foreach (var file in Directory.GetFiles(androidSdkPath))
foreach (var sourceFileName in Directory.GetFiles(androidSdkPath))
{
var destinationFile = Path.Combine(targetPath, Path.GetFileName(file));
if (!File.Exists(destinationFile))
{
File.Copy(file, destinationFile);
}
var fileName = Path.GetFileName(sourceFileName);
var destFileName = Path.Combine(targetPath, fileName);
_logger.LogDebug("Copying '{0}' to '{1}'", fileName, destFileName);

File.Copy(sourceFileName, destFileName, overwrite: true);
}
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,28 @@ public void CopyAndroidSdkToGradleProject_AndroidNativeSupportDisabledButSdkAlre
Directory.Delete(fakeProjectPath, true);
}

[Test]
public void CopyAndroidSdkToGradleProject_SdkAlreadyExists_OverwritesExistingSdk()
{
var fakeProjectPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
var unityProjectPath = Path.Combine(fakeProjectPath, "UnityProject");
var gradleProjectPath = Path.Combine(fakeProjectPath, "GradleProject");
DebugSymbolUploadTests.SetupFakeProject(fakeProjectPath);

var targetPath = Path.Combine(gradleProjectPath, "unityLibrary", "libs");
Directory.CreateDirectory(targetPath);
var existingFile = Path.Combine(targetPath, "androidSdk.jar");
File.WriteAllText(existingFile, "original content");

var sut = _fixture.GetSut();
sut.CopyAndroidSdkToGradleProject(unityProjectPath, gradleProjectPath);

var newContent = File.ReadAllBytes(existingFile);
Assert.AreNotEqual("original content", System.Text.Encoding.UTF8.GetString(newContent));

Directory.Delete(fakeProjectPath, true);
}

private string WithAndroidManifest(Action<string> callback)
{
var basePath = GetFakeManifestFileBasePath();
Expand Down
Loading