-
Notifications
You must be signed in to change notification settings - Fork 682
Xamarin.Build.Download package id validation causes build errors #1293
Description
I upgraded my Xamarin.Android project to Xamarin.Firebase.Storage to v120.x.x.x to take advantage of the newer firebase emulator APIs, which caused the build error "Invalid item ID firebaseappcheckinterop-16.0.0-beta01".
Related issues reported on StackOverflow:
https://stackoverflow.com/questions/68599578/xamarin-build-download-targets-invalid-id
https://stackoverflow.com/questions/69458719/i-get-the-error-invalid-item-id-firebaseappcheckinterop-16-0-0-beta01-during-b
Digging in, I've determined that the root cause is in Xamarin.Build.Download.DownloadUtils.ParseDownloadItems(..), which is highly opinionated on what should be considered a valid package id. Specifically, it expects that the version component of a package id (in this case, 16.0.0-beta01) should only use periods as separators. Since this version component uses a dash - before the beta01 postfix, the id check fails.
To confirm this, I cloned the XamarinComponents repo and modified the offending method to exclude the id check:
public IEnumerable<XamarinBuildDownload> ParseDownloadItems (ITaskItem[] items, bool allowUnsecureUrls)
{
if (items == null || items.Length <= 0)
return new List<XamarinBuildDownload> ();
var results = new List<XamarinBuildDownload> ();
foreach (var item in items) {
var xbd = new XamarinBuildDownload ();
xbd.Id = item.ItemSpec;
// !!!! THIS IS CAUSING BUILDS TO FAIL
//if (!ValidateId (xbd.Id)) {
// Log.LogCodedError (ErrorCodes.XbdInvalidItemId, "Invalid item ID {0}", xbd.Id);
// continue;
//}
xbd.Url = item.GetMetadata ("Url");
......
After packing the modified code and copying the output to my local nuget cache (replacing xamarin.build.download v0.10.0), my Xamarin.Android project compiled and ran without issue.
My recommendations for options to fix:
- Convince Google to stop including preview dependencies in non-preview packages 🙄
- Modify the id-checking logic in
DownloadUtilsto permit dash-delimiters OR - Remove the id-checking logic in
DownloadUtilsentirely. Unless there's a good reason for this that isn't apparent to me (which is totallypossiblelikely), it seems odd that Xamarin.Build.Download would assume responsibility for enforcing any specific package id/version format.