Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 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,15 @@ 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))
{
var destinationFile = Path.Combine(targetPath, Path.GetFileName(file));
if (!File.Exists(destinationFile))
{
File.Copy(file, destinationFile);
}
var fileName = Path.GetFileName(file);
_logger.LogDebug("Copying '{0}'", fileName);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To where? Above we log something with gradlePath but below we do targetPath


File.Copy(file, Path.Combine(targetPath, fileName), 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