Skip to content

Commit 4500d7d

Browse files
authored
[Xamarin.Android.Build.Tasks] run a Clean if the project path changes. (#7476)
Fixes #6924 If the user moves the project to another location on the hard drive the build will fail with errors such as. ``` APT2126 file not found. Foo.Foo C:\Foo.Foo\obj\Debug\net6.0-android\lp\122\jl\res\values\attr.xml 1 ``` To work around this we should place the `$(MSBuildProjectFullPath)` value in the `_PropertyCacheItems` ItemGroup. This will trigger a Clean if it changes.
1 parent c54222a commit 4500d7d

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/BuildTest2.cs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,39 @@ public void BuildBasicApplication ([ValueSource (nameof (SupportedTargetFramewor
118118
}
119119
}
120120

121+
[Test]
122+
[Category ("SmokeTests")]
123+
public void BuildBasicApplicationThenMoveIt ([Values (true, false)] bool isRelease)
124+
{
125+
string path = Path.Combine (Root, "temp", TestName, "App1");
126+
var proj = new XamarinAndroidApplicationProject {
127+
ProjectName = "App",
128+
IsRelease = isRelease,
129+
};
130+
using (var b = CreateApkBuilder (path)) {
131+
b.Target = "Build";
132+
Assert.IsTrue (b.Build (proj), "Build should have succeeded.");
133+
b.Target = "SignAndroidPackage";
134+
Assert.IsTrue (b.Build (proj), "SignAndroidPackage should have succeeded.");
135+
136+
137+
string path2 = Path.Combine (Root, "temp", TestName, "App2");
138+
if (Directory.Exists (path2))
139+
Directory.Delete (path2, recursive: true);
140+
Directory.Move (path, path2);
141+
b.ProjectDirectory = path2;
142+
foreach (var r in proj.AndroidResources)
143+
r.Timestamp = DateTime.UtcNow;
144+
b.Target = "Build";
145+
Assert.IsTrue (b.Build (proj, doNotCleanupOnUpdate: true, saveProject: false), "Build should have succeeded.");
146+
Assert.IsTrue (!b.Output.IsTargetSkipped ("_CleanIntermediateIfNeeded"), "_CleanIntermediateIfNeeded should be built.");
147+
Assert.IsTrue (!b.Output.IsTargetSkipped ("_CompileResources"), "_CompileResources Should have built.");
148+
b.Target = "SignAndroidPackage";
149+
Assert.IsTrue (b.Build (proj, doNotCleanupOnUpdate: true, saveProject: false), "SignAndroidPackage should have succeeded.");
150+
151+
}
152+
}
153+
121154
public static string GetLinkedPath (ProjectBuilder builder, bool isRelease, string filename)
122155
{
123156
return Builder.UseDotNet && isRelease ?

src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -981,6 +981,7 @@ because xbuild doesn't support framework reference assemblies.
981981
<_PropertyCacheItems Include="TypeMapKind=$(_TypeMapKind)" />
982982
<_PropertyCacheItems Include="AndroidSupportedAbis=$(AndroidSupportedAbis)" />
983983
<_PropertyCacheItems Include="AndroidManifestPlaceholders=$(AndroidManifestPlaceholders)" />
984+
<_PropertyCacheItems Include="ProjectFullPath=$(MSBuildProjectFullPath)" />
984985
</ItemGroup>
985986
<WriteLinesToFile
986987
File="$(_AndroidBuildPropertiesCache)"

0 commit comments

Comments
 (0)