Skip to content

Commit

Permalink
Merge pull request #8712 from unoplatform/dev/jela/net6-android-assets2
Browse files Browse the repository at this point in the history
fix(net6): [Android] Adjust for proper assets base path
  • Loading branch information
jeromelaban authored May 9, 2022
2 parents 0e07956 + f653bf5 commit cd24160
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion build/uno.winui.single-project.targets
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
<AndroidProjectFolder Condition=" '$(AndroidProjectFolder)' == '' ">Android\</AndroidProjectFolder>
<AndroidManifest>$(AndroidProjectFolder)AndroidManifest.xml</AndroidManifest>
<MonoAndroidResourcePrefix>$(AndroidProjectFolder)Resources</MonoAndroidResourcePrefix>
<MonoAndroidAssetsPrefix>$(AndroidProjectFolder)Assets;Assets</MonoAndroidAssetsPrefix>
<MonoAndroidAssetsPrefix>$(AndroidProjectFolder)Assets</MonoAndroidAssetsPrefix>

<!-- iOS -->
<EnableDefaultiOSItems>false</EnableDefaultiOSItems>
Expand Down
6 changes: 4 additions & 2 deletions src/SourceGenerators/Uno.UI.Tasks/Assets/RetargetAssets.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ public class RetargetAssets_v0 : Task
[Required]
public string TargetPlatform { get; set; }

public string AndroidAssetsPrefix { get; set; }

[Required]
public string DefaultLanguage { get; set; }

Expand Down Expand Up @@ -53,7 +55,7 @@ public override bool Execute()
break;
case "android":
resourceToTargetPath = resource => AndroidResourceConverter.Convert(resource, DefaultLanguage);
pathEncoder = AndroidResourceNameEncoder.EncodeFileSystemPath;
pathEncoder = s => AndroidResourceNameEncoder.EncodeFileSystemPath(s, AndroidAssetsPrefix ?? "Assets");
break;
default:
Log.LogMessage($"Skipping unknown platform {TargetPlatform}");
Expand All @@ -62,7 +64,7 @@ public override bool Execute()

Assets = ContentItems.ToArray();
RetargetedAssets = Assets
.Select((Func<ITaskItem, TaskItem>)(asset => ProcessContentItem(asset, resourceToTargetPath, pathEncoder)))
.Select(asset => ProcessContentItem(asset, resourceToTargetPath, pathEncoder))
.Where(a => a != null)
.ToArray();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
TargetPlatform="$(XamarinProjectType)"
DefaultLanguage="$(DefaultLanguage)"
ContentItems="@(Content)"
AndroidAssetsPrefix="$(MonoAndroidAssetsPrefix)"
Condition="'$(XamarinProjectType)'!=''">
<Output TaskParameter="Assets"
ItemName="Assets" />
Expand Down
4 changes: 2 additions & 2 deletions src/Uno.UWP/Helpers/AndroidResourceNameEncoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ public static string Encode(string key)
return key;
}

public static string EncodeFileSystemPath(string path)
public static string EncodeFileSystemPath(string path, string prefix = "Assets")
// Android assets need to placed in the Assets folder
=> global::System.IO.Path.Combine("Assets", EncodePath(path, global::System.IO.Path.DirectorySeparatorChar));
=> global::System.IO.Path.Combine(prefix, EncodePath(path, global::System.IO.Path.DirectorySeparatorChar));

public static string EncodeResourcePath(string path)
=> EncodePath(path, '/');
Expand Down

0 comments on commit cd24160

Please sign in to comment.