Skip to content

[Xamarin.Android.Build.Tasks] Use R.txt for Managed Resource Parser - #1058

Merged
jonpryor merged 1 commit into
dotnet:masterfrom
dellis1972:ParseRtxt
Dec 5, 2017
Merged

jonpryor merged 1 commit into
dotnet:masterfrom
dellis1972:ParseRtxt

Conversation

@dellis1972

@dellis1972 dellis1972 commented Nov 30, 2017 •

Copy link
Copy Markdown
Contributor

In order to speed up the processing of resources we should
make use of the R.txt files which are generally included with
.aar files and our components.

One advantage with this is we get the actual resource id which
is used by android. But it also means that when we do find an
R.txt file we can skip the processing of ALL resources in that
underlying res folder. Note this will only apply to the
ManagedResourceParser.

@dellis1972 dellis1972 added the do-not-merge PR should not be merged. label Nov 30, 2017
foreach (var dir in additionalResourceDirectories)
{
rTxt = Path.Combine(dir, "..", "R.txt");
if (File.Exists(rTxt))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This feels duplicative of the above code, in that the foreach (var dir in additionalResourceDirectories) block appears to be nearly identical to the previous block. Is there any way to "flatten" these?

foreach (var dir in new[]{resourceDirectory}.Concat(additionalResourceDirectories ?? new string[0])) {
    var rTxt = Path.Combine (dir, "..", "R.txt");
    if (File.Exists (rTxt)) {
        ProcessRtxtFile (rTxt);
        continue;
    }
    foreach (var file in Directory.GetFiles (dir, "*.*", SearchOption.AllDirectories)) {
        ProcessResourceFile (file);
    }
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

One of the reasons I split this up like this is because if we find a R.txt in the resourceDirectory that will have been generated by the app. As a result it will contain EVERYTHING. There will be no need to process anything else.

If its not there then we need to process everything else.

For the additionalResourceDirectories if we find an R.txt we can use that. but it will only contain the resources ids for that directory.. not everything.

Now I do have checks to make sure we don't add duplicates.. but this needs to be quick. And the quickest way to read a file is not too. So the more we can skip over the better.

}
for (int i = 0; i < count; i++)
c.Initializers.Add (new CodePrimitiveExpression (0));
{

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This brace is on the wrong line.

int value = 0;
if (i < values.Length)
value = values[i];
c.Initializers.Add(new CodePrimitiveExpression(value));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Missing space before (, here and elsewhere.


void ProcessRtxtFile (string file)
{
Console.WriteLine (file);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm assuming we don't want/need this debug spew...

switch (items [1]) {
case "anim":
CreateIntField (animation, itemName, value);
case "anim":

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do we need this whitespace change? (Are your IDE settings screwing things up again? ;-)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I was fixing the formatting.. the indentation of the case's was incorrect.

In order to speed up the processing of resources we should
make use of the R.txt files which are generally included with
.aar files and our components.

One advantage with this is we get the actual resource id which
is used by android. But it also means that when we do find an
R.txt file we can skip the processing of ALL resources in that
underlying `res` folder. Note this will only apply to the
ManagedResourceParser.
@dellis1972 dellis1972 changed the title [Xamarin.Android.Build.Tasks] Use R.txt for Managed Resource Parser [WIP] [Xamarin.Android.Build.Tasks] Use R.txt for Managed Resource Parser Dec 4, 2017
@dellis1972 dellis1972 removed the do-not-merge PR should not be merged. label Dec 4, 2017
@jonpryor
jonpryor merged commit fd96998 into dotnet:master Dec 5, 2017
jonpryor pushed a commit that referenced this pull request Jan 21, 2020
Changes: https://github.com/xamarin/monodroid/compare/2c9ce23d...dab75e88

Fixes: https://work.azdo.io/1041849
Fixes: https://developercommunity.visualstudio.com/content/problem/858509/adb0030-monoandroidtoolsrequiresuninstallexception-2.html

  * xamarin/monodroid@dab75e880: Bump to xamarin/android-sdk-installer/d16-5@5adcbfa (#1066)
  * xamarin/monodroid@3293f67a9: Bump to xamarin/android-sdk-installer/d16-5@dd6e2c0 (#1063)
  * xamarin/monodroid@8ecaa9d30: [tools/msbuild] prevent InstallPackageAssemblies from reporting two errors (#1058) (#1064)
  * xamarin/monodroid@284b81933: Bump to xamarin/androidtools/d16-5@62844ab (#1062)
@github-actions github-actions Bot locked and limited conversation to collaborators Feb 2, 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.

3 participants