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

[Xamarin.Android.Build.Tasks] fix for <Aapt/> #2880

Merged
merged 3 commits into from Mar 27, 2019

Conversation

jonathanpeppers
Copy link
Member

Context: http://build.devdiv.io/2527883

Our integration build for the Xamarin designer has caught a bug in the
following situation:

  • macOS-only (Windows is OK)
  • $(AndroidUseAapt2) is False
  • Using Xamarin.Android.Support.CustomTabs version 23.x

I was able to reproduce the problem by changing the
BuildTest.ResourceExtraction test.

The error message is:

/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(1765,2):
    error APT0000: resource directory '/private/var/folders/24/8k48jl6d249_n_qfxwsl6xvm0000gn/T/ADT-0/RT-MyDriving-1/MyDriving.Android/obj/Debug/resourcecache/3288F845948C6081AB114E82B328E204/res' does not exist

The reason this fails is that this particular library does not have a
res directory:

$ ls -l ~/.local/share/Xamarin/Xamarin.Android.Support.CustomTabs/23.1.1.0/embedded
total 64
 8 -rw-r--r--  1 jonathanpeppers  staff    861 Mar 26 11:18 AndroidManifest.xml
 0 drwxr-xr-x  3 jonathanpeppers  staff     96 Mar 26 11:18 aapt
56 -rw-r--r--  1 jonathanpeppers  staff  24743 Mar 26 11:18 classes.jar

The fix is to add a Directory.Exists check, this seems to fix the
unit test and the failing project used by the designer build.

Context: http://build.devdiv.io/2527883

Our integration build for the Xamarin designer has caught a bug in the
following situation:

* macOS-only (Windows is OK)
* `$(AndroidUseAapt2)` is `False`
* Using `Xamarin.Android.Support.CustomTabs` version 23.x

I was able to reproduce the problem by changing the
`BuildTest.ResourceExtraction` test.

The error message is:

    /Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(1765,2):
        error APT0000: resource directory '/private/var/folders/24/8k48jl6d249_n_qfxwsl6xvm0000gn/T/ADT-0/RT-MyDriving-1/MyDriving.Android/obj/Debug/resourcecache/3288F845948C6081AB114E82B328E204/res' does not exist

The reason this fails is that this particular library does not have a
`res` directory:

    $ ls -l ~/.local/share/Xamarin/Xamarin.Android.Support.CustomTabs/23.1.1.0/embedded
    total 64
     8 -rw-r--r--  1 jonathanpeppers  staff    861 Mar 26 11:18 AndroidManifest.xml
     0 drwxr-xr-x  3 jonathanpeppers  staff     96 Mar 26 11:18 aapt
    56 -rw-r--r--  1 jonathanpeppers  staff  24743 Mar 26 11:18 classes.jar

The fix is to add a `Directory.Exists` check, this seems to fix the
unit test *and* the failing project used by the designer build.
Add the `Directory.Exists` check for other directories
if (AdditionalAndroidResourcePaths != null)
foreach (var dir in AdditionalAndroidResourcePaths)
cmd.AppendSwitchIfNotNull ("-S ", Path.Combine (dir.ItemSpec.TrimEnd (System.IO.Path.DirectorySeparatorChar), "res"));
if (AdditionalResourceDirectories != null) {
Copy link
Member

Choose a reason for hiding this comment

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

Do we really need to repeat this much code, changing only the ITaskItem[] source?

For example, with C# local functions:

void AddResourceDirectories(ITaskItem[] directories) {
    if (directories == null) {
        return;
    }
    foreach (var dir in directories) {
        if (!Directory.Exists (dir.ItemSpec))
            continue;
        var resdir = dir.ItemSpec.TrimEnd ('\\');
        cmd.AppendSwitchIfNotNull ("-S ", resdir);
    }
}
AddResourceDirectories (AdditionalResourceDirectories);
AddResourceDirectories (AdditionalAndroidResourcePaths);

Copy link
Member Author

Choose a reason for hiding this comment

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

One does a Path.Combine (dir, "res") and the other does TrimEnd().

I could use a local function, here but I'd also have to do something like:

void AddResourceDirectories(ITaskItem[] directories, Func<string, string> func) {
    if (directories == null) {
        return;
    }
    foreach (var dir in directories) {
        if (!Directory.Exists (dir.ItemSpec))
            continue;
        var resdir = func (dir.ItemSpec);
        cmd.AppendSwitchIfNotNull ("-S ", resdir);
    }
}
AddResourceDirectories (AdditionalResourceDirectories, d => d.TrimEnd ('\\'));
AddResourceDirectories (AdditionalAndroidResourcePaths, d => Path.Combine (d, "res"));

At that point, not sure if it's simpler?

@jonpryor jonpryor merged commit c9c1f8a into xamarin:master Mar 27, 2019
@jonathanpeppers jonathanpeppers deleted the aapt-failure branch March 27, 2019 16:17
jonpryor pushed a commit that referenced this pull request Apr 3, 2019
Context: http://build.devdiv.io/2527883

Our integration build for the Xamarin designer has caught a bug in
the following situation:

  * `$(AndroidUseAapt2)` is `False`
  * Using `Xamarin.Android.Support.CustomTabs` version 23.x

I was able to reproduce the problem by changing the
`BuildTest.ResourceExtraction()` test.

The error message is:

	/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(1765,2):
	    error APT0000: resource directory '/private/var/folders/24/8k48jl6d249_n_qfxwsl6xvm0000gn/T/ADT-0/RT-MyDriving-1/MyDriving.Android/obj/Debug/resourcecache/3288F845948C6081AB114E82B328E204/res' does not exist

The reason this fails is that this particular library does not have a
`res` directory:

	$ ls -l ~/.local/share/Xamarin/Xamarin.Android.Support.CustomTabs/23.1.1.0/embedded
	total 64
	 8 -rw-r--r--  1 jonathanpeppers  staff    861 Mar 26 11:18 AndroidManifest.xml
	 0 drwxr-xr-x  3 jonathanpeppers  staff     96 Mar 26 11:18 aapt
	56 -rw-r--r--  1 jonathanpeppers  staff  24743 Mar 26 11:18 classes.jar

The fix is to add a `Directory.Exists()` check, this seems to fix the
unit test *and* the failing project used by the designer build.

Additionally, the test should be `[NonParallelizable]`, just in case
the NuGet packages were being restored multiple times from multiple
processes.
@github-actions github-actions bot locked and limited conversation to collaborators Jan 31, 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.

None yet

3 participants