Skip to content

Commit 4327a3f

Browse files
authored
fix: Overwrite Android SDK during build (#2031)
1 parent 24c8431 commit 4327a3f

File tree

3 files changed

+36
-6
lines changed

3 files changed

+36
-6
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## Unreleased
4+
5+
### Fixes
6+
7+
- 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))
8+
39
## 3.0.1
410

511
### Fixes

src/Sentry.Unity.Editor/Android/AndroidManifestConfiguration.cs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -228,14 +228,16 @@ internal void CopyAndroidSdkToGradleProject(string unityProjectPath, string grad
228228
throw new DirectoryNotFoundException($"Failed to find the Android SDK at '{androidSdkPath}'.");
229229
}
230230

231+
Directory.CreateDirectory(targetPath);
232+
231233
_logger.LogInfo("Copying the Android SDK to '{0}'.", gradlePath);
232-
foreach (var file in Directory.GetFiles(androidSdkPath))
234+
foreach (var sourceFileName in Directory.GetFiles(androidSdkPath))
233235
{
234-
var destinationFile = Path.Combine(targetPath, Path.GetFileName(file));
235-
if (!File.Exists(destinationFile))
236-
{
237-
File.Copy(file, destinationFile);
238-
}
236+
var fileName = Path.GetFileName(sourceFileName);
237+
var destFileName = Path.Combine(targetPath, fileName);
238+
_logger.LogDebug("Copying '{0}' to '{1}'", fileName, destFileName);
239+
240+
File.Copy(sourceFileName, destFileName, overwrite: true);
239241
}
240242
}
241243
else

test/Sentry.Unity.Editor.Tests/Android/AndroidManifestConfigurationTests.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,28 @@ public void CopyAndroidSdkToGradleProject_AndroidNativeSupportDisabledButSdkAlre
421421
Directory.Delete(fakeProjectPath, true);
422422
}
423423

424+
[Test]
425+
public void CopyAndroidSdkToGradleProject_SdkAlreadyExists_OverwritesExistingSdk()
426+
{
427+
var fakeProjectPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
428+
var unityProjectPath = Path.Combine(fakeProjectPath, "UnityProject");
429+
var gradleProjectPath = Path.Combine(fakeProjectPath, "GradleProject");
430+
DebugSymbolUploadTests.SetupFakeProject(fakeProjectPath);
431+
432+
var targetPath = Path.Combine(gradleProjectPath, "unityLibrary", "libs");
433+
Directory.CreateDirectory(targetPath);
434+
var existingFile = Path.Combine(targetPath, "androidSdk.jar");
435+
File.WriteAllText(existingFile, "original content");
436+
437+
var sut = _fixture.GetSut();
438+
sut.CopyAndroidSdkToGradleProject(unityProjectPath, gradleProjectPath);
439+
440+
var newContent = File.ReadAllBytes(existingFile);
441+
Assert.AreNotEqual("original content", System.Text.Encoding.UTF8.GetString(newContent));
442+
443+
Directory.Delete(fakeProjectPath, true);
444+
}
445+
424446
private string WithAndroidManifest(Action<string> callback)
425447
{
426448
var basePath = GetFakeManifestFileBasePath();

0 commit comments

Comments
 (0)