Skip to content

Commit f900a76

Browse files
committed
Add Error for Library Projects
1 parent d76375b commit f900a76

File tree

6 files changed

+54
-0
lines changed

6 files changed

+54
-0
lines changed

Documentation/guides/messages/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ package from all the users on device and try again. If that does not work you ca
100100
Fast Deployment is not currently supported on this device.
101101
Please file an issue with the exact error message using the 'Help->Send Feedback->Report a Problem' menu item in Visual Studio
102102
or 'Help->Report a Problem' in Visual Studio for Mac.
103+
+ [XA0138](xa0138.md): @(AndroidAsset) build action does not support 'AssetPack' Metadata in Library Projects.
103104

104105
## XA1xxx: Project related
105106

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
title: Xamarin.Android error XA0138
2+
description: XA0138 error code
3+
ms.date: 02/05/2024
4+
---
5+
# Xamarin.Android error XA0138
6+
7+
## Issue
8+
9+
@(AndroidAsset) build action does not support 'AssetPack' or 'DeliveryType' Metadata in Library Projects.
10+
11+
## Solution
12+
13+
Remove the 'AssetPack' or 'DeliveryType' Metadata from your `AndroidAsset` build Items.

src/Xamarin.Android.Build.Tasks/MSBuild/Xamarin/Android/Xamarin.Android.Assets.targets

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,17 @@ Copyright (C) 2011-2012 Xamarin. All rights reserved.
7474
</ItemGroup>
7575
</Target>
7676

77+
<Target Name="_CheckForAssetPackInLibraryProject" Condition=" '$(AndroidApplication)' != 'true' ">
78+
<ItemGroup>
79+
<_AssetsWithAssetPackMetaData Include="@(AndroidAsset)" Condition=" '%(AndroidAsset.AssetPack)' != '' " />
80+
</ItemGroup>
81+
<AndroidError
82+
Code="XA0138"
83+
ResourceName="XA0138"
84+
Condition=" '@(_AssetsWithAssetPackMetaData->Count())' != '0' "
85+
/>
86+
</Target>
87+
7788
<Target Name="_CalculateAssetPacks"
7889
Condition=" ('$(AndroidPackageFormat)' == 'aab' And '$(AndroidApplication)' == 'true') "
7990
>

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ properties that determine build ordering.
7676
_LintChecks;
7777
_IncludeNativeSystemLibraries;
7878
_CheckGoogleSdkRequirements;
79+
_BuildAssetPacks;
7980
</_PrepareBuildApkDependsOnTargets>
8081
</PropertyGroup>
8182

@@ -91,6 +92,7 @@ properties that determine build ordering.
9192
_AddAndroidDefines;
9293
_CheckForContent;
9394
_CheckForObsoleteFrameworkAssemblies;
95+
_CheckForAssetPackInLibraryProject;
9496
_RemoveLegacyDesigner;
9597
_ValidateAndroidPackageProperties;
9698
AddLibraryJarsToBind;

src/Xamarin.Android.Build.Tasks/Properties/Resources.resx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,10 @@ If this file comes from a NuGet package, update to a newer version of the NuGet
329329
The capitalized word "Portable" that appears earlier in the message is plain text and should be translated, but the lowercase word "portable" later in the message is a literal value and should not be translated.
330330
{0} - The file name of a deprecated symbol file</comment>
331331
</data>
332+
<data name="XA0138" xml:space="preserve">
333+
<value>@(AndroidAsset) build action does not support 'AssetPack' or 'DeliveryType' Metadata in Library Projects.</value>
334+
<comment></comment>
335+
</data>
332336
<data name="XA1000" xml:space="preserve">
333337
<value>There was a problem parsing {0}. This is likely due to incomplete or invalid XML. Exception: {1}</value>
334338
<comment>{0} - The file name

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,29 @@ namespace Xamarin.Android.Build.Tests
1010
[Parallelizable (ParallelScope.Children)]
1111
public class AssetPackTests : BaseTest
1212
{
13+
[Test]
14+
[Category ("SmokeTests")]
15+
public void BuildLibraryWithAssetPack ([Values (true, false)] bool isRelease)
16+
{
17+
var path = Path.Combine ("temp", TestName);
18+
var lib = new XamarinAndroidLibraryProject {
19+
IsRelease = isRelease,
20+
OtherBuildItems = {
21+
new AndroidItem.AndroidAsset ("Assets\\asset1.txt") {
22+
TextContent = () => "Asset1",
23+
Encoding = Encoding.ASCII,
24+
MetadataValues="AssetPack=assetpack1",
25+
},
26+
}
27+
};
28+
using (var builder = CreateDllBuilder (Path.Combine (path, lib.ProjectName))) {
29+
builder.ThrowOnBuildFailure = false;
30+
Assert.IsFalse (builder.Build (lib), $"{lib.ProjectName} should fail.");
31+
StringAssertEx.Contains ("error XA0138: @(AndroidAsset) build action does not support 'AssetPack' or 'DeliveryType' Metadata in Library Projects.", builder.LastBuildOutput,
32+
"Build Output did not contain error XA0138'.");
33+
}
34+
}
35+
1336
[Test]
1437
[Category ("SmokeTests")]
1538
public void BuildApplicationWithAssetPackOverrides ([Values (true, false)] bool isRelease)

0 commit comments

Comments
 (0)