Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

InstallAndroidDependencies target does not install platforms or build-tools components on Windows #4677

Closed
brendanzagaeski opened this issue May 12, 2020 · 3 comments
Assignees
Labels
Area: Commercial Issues with non-OSS components.

Comments

@brendanzagaeski
Copy link
Contributor

brendanzagaeski commented May 12, 2020

Example steps to reproduce

Adjust the InstallAndroidDependenciesTest to assert that the target Android SDK install directories are created:

diff --git a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/AndroidDependenciesTests.cs b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/AndroidDependenciesTests.cs
index 73c32881..62066963 100644
--- a/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/AndroidDependenciesTests.cs
+++ b/src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/AndroidDependenciesTests.cs
@@ -24,6 +24,8 @@ namespace Xamarin.Android.Build.Tests
 					string defaultTarget = b.Target;
 					b.Target = "InstallAndroidDependencies";
 					Assert.IsTrue (b.Build (proj, parameters: new string [] { "AcceptAndroidSDKLicenses=true" }), "InstallAndroidDependencies should have succeeded.");
+					Assert.IsTrue (Directory.Exists (Path.Combine (sdkPath, "platforms")), "At least one platform should have been installed");
+					Assert.IsTrue (Directory.Exists (Path.Combine (sdkPath, "build-tools")), "At least one Build Tools version should have been installed");
 					b.Target = defaultTarget;
 					Assert.IsTrue (b.Build (proj), "build should have succeeded.");
 				}

Expected behavior

The test passes when running on Windows. The corresponding build log should include lines that start with:

Downloading archive from ...

and some lines like:

Installing Android SDK component: Android SDK Platform 29 r4 [Platform: API 29]

Actual behavior

The test fails on Windows. The build does not include any Downloading archive or Installing Android SDK component lines. Instead it shows:

No components need to be installed

Preliminary investigation

This appears to be a path separator issue. I tried an experiment where I replaced dependency.ItemSpec with string.Join ("\\", dependency.ItemSpec.Split ('/')) in the commercial <InstallAndroidDependencies/> task. That allowed the Downloading archive and Installing Android SDK component messages to appear as expected.

Version info

xamarin/android-sdk-installer@4ce982e5b50be23a7df2d3f244e325c2b82254c9

@brendanzagaeski brendanzagaeski added the Area: Commercial Issues with non-OSS components. label May 12, 2020
@brendanzagaeski brendanzagaeski added this to the Under Consideration milestone May 12, 2020
@brendanzagaeski
Copy link
Contributor Author

Maybe a fix could be to adjust <CalculateProjectDependencies/> to use Path.Combine() in the following lines? https://github.com/xamarin/xamarin-android/blob/375e06236bc6947c69da92b0e45bb6f8dca94221/src/Xamarin.Android.Build.Tasks/Tasks/CalculateProjectDependencies.cs#L56-L57

@brendanzagaeski brendanzagaeski changed the title InstallAndroidDependencies target does not install anything on Windows InstallAndroidDependencies target does not install platforms or build-tools components on Windows May 12, 2020
brendanzagaeski added a commit to brendanzagaeski/xamarin-android that referenced this issue May 13, 2020
…Dependencies/>

Fixes: dotnet#4677

`<CalculateProjectDependencies/>` was always using `/` as the path
separator for the `build-tools` and `platforms` output items:

	Task "CalculateProjectDependencies"
	  Task Parameter:TargetFrameworkVersion=v10.0
	  Task Parameter:ManifestFile=C:\Source\xamarin-android\bin\TestDebug\temp\InstallAndroidDependenciesTest\Project\Properties\AndroidManifest.xml
	  Task Parameter:BuildToolsVersion=29.0.2
	  Task Parameter:PlatformToolsVersion=29.0.5
	  Task Parameter:ToolsVersion=26.1.1
	  Task Parameter:NdkVersion=16.1
	  Task Parameter:NdkRequired=False
	  Output Item(s):
	      AndroidDependency=
	          platforms/android-29
	          build-tools/29.0.2
	                  Version=29.0.2
	          platform-tools
	                  Version=29.0.5
	          tools
	                  Version=26.1.1
	Done executing task "CalculateProjectDependencies".

This meant the commercial `<InstallAndroidDependencies/>` task wouldn't
ever install the `build-tools` or `platforms` components on Windows
because none of the candidate `IAndroidComponent.FileSystemPath` values
that were available via the SDK installer matched the input
`ITaskItem.ItemSpec` values.

Fix this by changing `<CalculateProjectDependencies/>` to use
`Path.Combine()` instead of `/`.

Test changes:

`InstallAndroidDependenciesTest` did not yet enforce the expected
behavior for this bug because `<ResolveSdks/>` was automatically falling
back to the default Android SDK installation.

Update `InstallAndroidDependenciesTest` to enforce the expected
behavior.

To minimize download requirements for the test, add a mock
`tools/source.properties` file to the target `android-sdk` directory
during each test run.  This reduces the total downloads from about 1 GB
to under 100 MB, and, because the `tools` component isn't needed for the
current default project configuration, `b.Build (proj)` still completes
successfully.
@brendanzagaeski
Copy link
Contributor Author

Release status update

I have locally verified that the non-public fix from https://github.com/xamarin/android-sdk-installer/commit/2b4d1a6a4c49c3bc3fc9751726d854d75c617434, included in 2cf80f5 resolves this issue.

A new Preview version of Xamarin.Android has now been published that includes the fix for this item. The fix is not yet included in a Release version. I will update this item again when a Release version is available that includes the fix.

Fix included in Xamarin.Android SDK version 11.1.0.15.

Fix included on Windows in Visual Studio 2019 version 16.8 Preview 4. To try the Preview version that includes the fix, check for the latest updates in Visual Studio Preview.

Fix included on macOS in Visual Studio 2019 for Mac version 8.8 Preview 4. To try the Preview version that includes the fix, check for the latest updates on the Preview updater channel.

@brendanzagaeski
Copy link
Contributor Author

Release status update

A new Release version of Xamarin.Android has now been published that includes the fix for this item.

Fix included in Xamarin.Android SDK version 11.1.0.17.

Fix included on Windows in Visual Studio 2019 version 16.8. To get the new version that includes the fix, check for the latest updates or install the most recent release from https://visualstudio.microsoft.com/downloads/.

Fix included on macOS in Visual Studio 2019 for Mac version 8.8. To get the new version that includes the fix, check for the latest updates on the Stable updater channel.

@ghost ghost locked as resolved and limited conversation to collaborators Jun 4, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Area: Commercial Issues with non-OSS components.
Projects
None yet
3 participants