Bug 27471 - Allow Android Resources to be in subdirectories
Summary: Allow Android Resources to be in subdirectories
Alias: None
Product: Android
Classification: Xamarin
Component: General ()
Version: 5.1
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: ---
Assignee: Jonathan Pryor
Depends on:
Reported: 2015-02-26 14:26 UTC by Justin Toth
Modified: 2015-03-08 21:46 UTC (History)
1 user (show)

Is this bug a regression?: ---
Last known good build:

Proposed file structure (135.14 KB, image/png)
2015-02-26 14:26 UTC, Justin Toth

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Justin Toth 2015-02-26 14:26:04 UTC
Created attachment 10063 [details]
Proposed file structure

In native Android development your layout and drawable folders have to be directly in Resources and then your axml, png, etc... files have to be directly within those folders. This leads to a couple of issues:

1. Having a long list of directories within Resources (especially once you start supporting multiple screen sizes / orientations.)

2. Having a long list of files within layout, drawables-xhdpi, drawables-hdpi, and so on.

I believe we can leverage the abstraction layer that is Xamarin to our advantage here, so that we can support subdirectories and still not blow up native Android. Here is what I propose to fix issue #1:

1. We allow any folder to be created within Resources rather than just the standard Android ones, so the "Invalid resource directory name" validation would be removed (or modified to detect whether the "invalid" directory has "valid" directories beneath it.) You could then create directories within Resources, e.g. "drawables", and then move folders underneath it, e.g. drawable-xhdpi, drawable-hdpi, and drawable-mdpi.

2. When the application is compiled and outputted to the build directory, the build process would recursively loop through all directories and subdirectories within Resources. Any subdirectories that don't have subdirectories within them would be copied to the root of Resources in the build output. Alternatively you could check for any directories that have a valid Resource name and copy those to the root of Resources. Any left over directories would be deleted from the build output. This would ensure that the Android application build output would be exactly the same as if there weren't subdirectories.

To fix issue #2, we would similarly allow subdirectories within the "valid" resource directories. The layout axml files, image files, etc.. could be within these subdirectories, then at build time we would simply copy the files down from the subdirectories into the parent that has a "valid" resource name, then delete the empty subdirectories left over.

I hope this ticket will be considered, as it's annoying having long lists of directories and files under Resources. Below is a screenshot of what the directory structure could look like after resolving issue #1.
Comment 1 Jonathan Pryor 2015-02-27 09:30:43 UTC
Thank you for the suggestion, but we do not plan on implementing this feature.
Comment 2 Mikayla Hutchinson [MSFT] 2015-03-08 21:46:52 UTC
FWIW, if you want to split your resources into multiple directories, you can provide multiple values for MonoAndroidResourcePrefix, as documented here: http://developer.xamarin.com/guides/android/under_the_hood/build_process/