Skip to content

Conversation

@brendanzagaeski
Copy link
Contributor

Fixes: #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.

…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.
var sdkVersion = Math.Max (targetApiLevel.Value, manifestApiLevel);
dependencies.Add (CreateAndroidDependency ($"platforms/android-{sdkVersion}", $""));
dependencies.Add (CreateAndroidDependency ($"build-tools/{BuildToolsVersion}", BuildToolsVersion));
dependencies.Add (CreateAndroidDependency (Path.Combine ("platforms", $"android-{sdkVersion}"), $""));
Copy link
Contributor

Choose a reason for hiding this comment

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

This must have changed behaviour in the sdk installer. I seem to remember the spec required the system to use / as a separator :/

Copy link
Contributor

Choose a reason for hiding this comment

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

Relevant spec: https://microsoft-my.sharepoint.com/:w:/p/mhutch/ETjdNgT_yfJMszzuRRW2hUYB133Goo831A5U2rAFwgI8bA?e=77b68c4ccf5841139a242a0d99cd0368

Forward slash / is explicitly mentioned in the spec:

For items in the main Android repository manifest, the ID shall be the path formatted in *nix format, e.g. “platforms/android-25” or “ndk-bundle”. For add-ons, the ID shall be the add-on’s “name-id” property. We will also have our own manifest format where the fileSystemPath will be exposed directly.

We do not want to use Path.Combine() here.

Copy link
Contributor

Choose a reason for hiding this comment

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

So in that case the issue must be in the task which calls the SDK Manager or the SDK Manager code itself I guess.

@dellis1972
Copy link
Contributor

Interestingly on windows doing the following does not install anything

/t:InstallAndroidDependencies /p:AndroidSdkDirectory=c:\Sandbox\sdk /p:AcceptAndroidSDKLicenses=true

where the sdk folder is empty. I would expect it to install everything the project needs. This is what we are telling our customers, and it used to work. I have a feeling that something in the InstallAndroidDependencies or the sdk installer itself is not behaving correctly now. We should investigate that to fix the issue in the sdk-installer.

@dellis1972
Copy link
Contributor

It works fine on a Mac.

@dellis1972
Copy link
Contributor

This was fixed in https://github.com/xamarin/android-sdk-installer/pull/452 so we can close this PR.

@dellis1972 dellis1972 closed this Aug 24, 2020
@github-actions github-actions bot locked and limited conversation to collaborators Jan 24, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

3 participants