Skip to content

Commit 17c5317

Browse files
[xabt] fix DeployToDevice target w/ Fast Deployment (#10641)
In cd88d9c, we introduced a new `DeployToDevice` target for new `dotnet run` support. However, the following `Condition` doesn't work due to build order: <DeployToDeviceDependsOnTargets Condition=" '$(_XASupportsFastDev)' == 'true' "> $(_MinimalSignAndroidPackageDependsOn); _Upload; </DeployToDeviceDependsOnTargets> <DeployToDeviceDependsOnTargets Condition=" '$(_XASupportsFastDev)' != 'true' "> $(_MinimalSignAndroidPackageDependsOn); _DeployApk; _DeployAppBundle; </DeployToDeviceDependsOnTargets> * `Microsoft.Android.Sdk.BuildOrder.targets` is imported right before `Xamarin.Android.Common.targets` where `$(_XASupportsFastDev)` is set. To fix this: * Let's rename `$(_XASupportsFastDev)` to `$(_AndroidFastDeploymentSupported)` to just modernize the name. * Move `$(_AndroidFastDeploymentSupported)` to `Microsoft.Android.Sdk.DefaultProperties.targets` that is imported early on. * Update a test to verify the proper targets run in `DeployToDevice` target.
1 parent b58d460 commit 17c5317

File tree

7 files changed

+24
-12
lines changed

7 files changed

+24
-12
lines changed

src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.Application.targets

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ This file contains targets specific for Android application projects.
1414

1515
<PropertyGroup>
1616
<!-- If Xamarin.Android.Common.Debugging.targets exists, we can rely on _Run for debugging. -->
17-
<_RunDependsOn Condition=" '$(_XASupportsFastDev)' == 'true' ">
17+
<_RunDependsOn Condition=" '$(_AndroidFastDeploymentSupported)' == 'true' ">
1818
Install;
1919
_Run;
2020
</_RunDependsOn>
21-
<_RunDependsOn Condition=" '$(_XASupportsFastDev)' != 'true' ">
21+
<_RunDependsOn Condition=" '$(_AndroidFastDeploymentSupported)' != 'true' ">
2222
Install;
2323
StartAndroidActivity;
2424
</_RunDependsOn>

src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.BuildOrder.targets

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,11 @@ properties that determine build ordering.
125125
$(_MinimalSignAndroidPackageDependsOn);
126126
</SignAndroidPackageDependsOn>
127127
<!-- This should function similar to SignAndroidPackage inside VS plus also deploy -->
128-
<DeployToDeviceDependsOnTargets Condition=" '$(_XASupportsFastDev)' == 'true' ">
128+
<DeployToDeviceDependsOnTargets Condition=" '$(_AndroidFastDeploymentSupported)' == 'true' ">
129129
$(_MinimalSignAndroidPackageDependsOn);
130130
_Upload;
131131
</DeployToDeviceDependsOnTargets>
132-
<DeployToDeviceDependsOnTargets Condition=" '$(_XASupportsFastDev)' != 'true' ">
132+
<DeployToDeviceDependsOnTargets Condition=" '$(_AndroidFastDeploymentSupported)' != 'true' ">
133133
$(_MinimalSignAndroidPackageDependsOn);
134134
_DeployApk;
135135
_DeployAppBundle;

src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.DefaultProperties.targets

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
<GenerateDependencyFile Condition=" '$(GenerateDependencyFile)' == '' ">false</GenerateDependencyFile>
1818
<CopyLocalLockFileAssemblies Condition=" '$(CopyLocalLockFileAssemblies)' == '' ">false</CopyLocalLockFileAssemblies>
1919
<ComputeNETCoreBuildOutputFiles Condition=" '$(ComputeNETCoreBuildOutputFiles)' == '' ">false</ComputeNETCoreBuildOutputFiles>
20+
<_AndroidFastDeploymentSupported Condition=" Exists ('$(MSBuildThisFileDirectory)../tools/Xamarin.Android.Common.Debugging.targets') ">true</_AndroidFastDeploymentSupported>
21+
<_AndroidFastDeploymentSupported Condition=" '$(_AndroidFastDeploymentSupported)' == '' ">False</_AndroidFastDeploymentSupported>
22+
2023
<!--
2124
Disable @(Content) from referenced projects
2225
See: https://github.com/dotnet/sdk/blob/955c0fc7b06e2fa34bacd076ed39f61e4fb61716/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Publish.targets#L16

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1207,9 +1207,9 @@ public void FastDeploymentDoesNotAddContentProvider ([Values (AndroidRuntime.Mon
12071207
EmbedAssembliesIntoApk = false,
12081208
};
12091209
proj.SetRuntime (runtime);
1210-
proj.SetProperty ("_XASupportsFastDev", "True");
1210+
proj.SetProperty ("_AndroidFastDeploymentSupported", "true");
12111211
using (var b = CreateApkBuilder ()) {
1212-
//NOTE: build will fail, due to $(_XASupportsFastDev)
1212+
//NOTE: build will fail, due to $(_AndroidFastDeploymentSupported)
12131213
b.ThrowOnBuildFailure = false;
12141214
b.Build (proj);
12151215

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public void XA0119 ()
7979
AssertCommercialBuild ();
8080

8181
var proj = new XamarinAndroidApplicationProject ();
82-
proj.SetProperty ("_XASupportsFastDev", "True");
82+
proj.SetProperty ("_AndroidFastDeploymentSupported", "true");
8383
proj.SetProperty (proj.DebugProperties, "AndroidLinkMode", "Full");
8484
using (var b = CreateApkBuilder ()) {
8585
b.Target = "Build"; // SignAndroidPackage would fail for OSS builds
@@ -94,7 +94,7 @@ public void XA0119AAB ()
9494
AssertCommercialBuild ();
9595

9696
var proj = new XamarinAndroidApplicationProject ();
97-
proj.SetProperty ("_XASupportsFastDev", "True");
97+
proj.SetProperty ("_AndroidFastDeploymentSupported", "true");
9898
proj.SetProperty ("AndroidPackageFormat", "aab");
9999
using (var builder = CreateApkBuilder ()) {
100100
builder.ThrowOnBuildFailure = false;

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,6 @@ Copyright (C) 2011-2012 Xamarin. All rights reserved.
154154
<!-- Version/fx properties -->
155155
<PropertyGroup>
156156
<_XAMajorVersionNumber>1</_XAMajorVersionNumber>
157-
<_XASupportsFastDev Condition=" Exists ('$(MSBuildThisFileDirectory)Xamarin.Android.Common.Debugging.targets') ">True</_XASupportsFastDev>
158-
<_XASupportsFastDev Condition=" '$(_XASupportsFastDev)' == '' ">False</_XASupportsFastDev>
159157
<AndroidUseInterpreter Condition=" '$(AndroidUseInterpreter)' == '' ">$(UseInterpreter)</AndroidUseInterpreter>
160158
<AndroidUseInterpreter Condition=" '$(AndroidUseInterpreter)' == '' ">False</AndroidUseInterpreter>
161159
<AndroidApplication Condition="'$(AndroidApplication)' == ''">false</AndroidApplication>
@@ -165,8 +163,8 @@ Copyright (C) 2011-2012 Xamarin. All rights reserved.
165163
<TargetFrameworkIdentifier Condition="'$(TargetFrameworkIdentifier)' == ''">MonoAndroid</TargetFrameworkIdentifier>
166164
<MonoAndroidVersion>v$(_XAMajorVersionNumber).0</MonoAndroidVersion>
167165
<AndroidUpdateResourceReferences Condition="'$(AndroidUpdateResourceReferences)' == ''">True</AndroidUpdateResourceReferences>
168-
<EmbedAssembliesIntoApk Condition=" '$(EmbedAssembliesIntoApk)' == '' And '$(Optimize)' != 'True' And '$(_XASupportsFastDev)' == 'True' ">False</EmbedAssembliesIntoApk>
169-
<EmbedAssembliesIntoApk Condition=" '$(_XASupportsFastDev)' == 'False' ">True</EmbedAssembliesIntoApk>
166+
<EmbedAssembliesIntoApk Condition=" '$(EmbedAssembliesIntoApk)' == '' And '$(Optimize)' != 'True' And '$(_AndroidFastDeploymentSupported)' == 'True' ">False</EmbedAssembliesIntoApk>
167+
<EmbedAssembliesIntoApk Condition=" '$(_AndroidFastDeploymentSupported)' == 'False' ">True</EmbedAssembliesIntoApk>
170168
<EmbedAssembliesIntoApk Condition=" '$(EmbedAssembliesIntoApk)' == '' ">True</EmbedAssembliesIntoApk>
171169
<AndroidPreferNativeLibrariesWithDebugSymbols Condition=" '$(AndroidPreferNativeLibrariesWithDebugSymbols)' == '' ">False</AndroidPreferNativeLibrariesWithDebugSymbols>
172170
<AndroidSkipJavacVersionCheck Condition="'$(AndroidSkipJavacVersionCheck)' == ''">False</AndroidSkipJavacVersionCheck>

tests/MSBuildDeviceIntegration/Tests/InstallAndRunTests.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,17 @@ public void DeployToDevice (bool isRelease)
6868
Assert.IsTrue (dotnet.Build (), "`dotnet build` should succeed");
6969
Assert.IsTrue (dotnet.Build ("DeployToDevice"), "`dotnet build -t:DeployToDevice` should succeed");
7070

71+
// Verify correct targets ran based on FastDev support
72+
if (TestEnvironment.CommercialBuildAvailable) {
73+
dotnet.AssertTargetIsNotSkipped ("_Upload");
74+
dotnet.AssertTargetIsSkipped ("_DeployApk", defaultIfNotUsed: true);
75+
dotnet.AssertTargetIsSkipped ("_DeployAppBundle", defaultIfNotUsed: true);
76+
} else {
77+
dotnet.AssertTargetIsSkipped ("_Upload", defaultIfNotUsed: true);
78+
dotnet.AssertTargetIsNotSkipped ("_DeployApk");
79+
dotnet.AssertTargetIsNotSkipped ("_DeployAppBundle");
80+
}
81+
7182
// Launch the app using adb
7283
ClearAdbLogcat ();
7384
var result = AdbStartActivity ($"{proj.PackageName}/{proj.JavaPackageName}.MainActivity");

0 commit comments

Comments
 (0)