Skip to content

Commit 88572f8

Browse files
dellis1972jonpryor
authored andcommitted
[Xamarin.Android.Build.Tasks] Ensure Library views are updated (#3218)
Fixes: #3123 Scenario: 1. Create a Solution in which the `App.csproj` references a `MonoAndroid`-profile `Library.csproj` project. 2. `Library.csproj` contains an `Android.Views.View` subclass. 3. `Library.csproj` contains an `@(AndroidResource)` with a layout `.axml` file which uses the `View` from (2) 4. `App` project uses (2) with `Activity.SetContentView()`. 5. Build & Run the project; it works. 6. Update the `View` subclass from (2). 7. Build & run the project. Step (7) is expected to result in a successful app launch. Instead, it fails during process startup: Android.Views.InflateException: Binary XML file line #1: Binary XML file line #1: Error inflating class InflatedLibrary.CodeBehindClass occurred Commit 373c6ed added a new `_ConvertCustomView` target to handle the conversion of custom view to the md5 hash versions. While it worked *most* of the time, there was a very specific area where it was not fixing up the custom views. This problem only occurs when a library project code is updated, as with step (6). When happens next is that when the main app builds and the library resources are then re-extracted into the `$(IntermediateOutputPath)lp\XX\ji\res` directory. The `<ConvertResorucesCases/>` task is then run to fixup those `res` files with the correct casing. Then the `<GenerateJavaStubs/>` task is run, because the library project was updated. However at this point the wheels fall of the wagon because the `_ConvertCustomViews` target does NOT run. This is because it is only using the following inputs: $(_CustomViewMapFile);$(_AcwMapFile) Neither of these files are updated in this instance. `$(_AcwMapFile)` will only be updated if a class or namespace are changed. If code within a class is changed in a way which doesn't alter the class or namespace name, then nothing in the ACW map will need to be updated, so we don't update the file. The `$(_CustomViewMapFile)` is also not updated, unless resources are added or removed. So that doesn't change either. The result is the target is skipped, and we end up with a custom view which does NOT have the correct type names. This results in the above error. The fix in this case is to update the Inputs of the `_ConvertCustomView` target to have the following $(_CustomViewMapFile);$(_AcwMapFile);@(_AndroidResourceDest);@(_LibraryResourceDirectoryStamps) By including these two extra items we can make sure the target runs if either an app resource is updated or if a library project changes. A unit test has been updated to test for this particular issue.
1 parent 75cde13 commit 88572f8

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,17 @@ protected override void OnClick()
464464
"Warning while processing resources should not have been raised.");
465465
Assert.IsTrue (b.Build (proj, doNotCleanupOnUpdate: true), "Build should have succeeded.");
466466
Assert.IsTrue (b.Output.IsTargetSkipped ("_GenerateJavaStubs"), "Target _GenerateJavaStubs should have been skipped");
467+
468+
lib.Touch ("CustomTextView.cs");
469+
470+
Assert.IsTrue (libb.Build (lib, doNotCleanupOnUpdate: true, saveProject: false), "second library build should have succeeded.");
471+
Assert.IsTrue (b.Build (proj, doNotCleanupOnUpdate: true, saveProject: false), "second app build should have succeeded.");
472+
473+
using (var zip = ZipHelper.OpenZip (packaged_resources)) {
474+
CheckCustomView (zip, intermediate, "lp", "0", "jl", "res", "layout", "custom_text_lib.xml");
475+
CheckCustomView (zip, intermediate, "res", "layout", "custom_text_app.xml");
476+
}
477+
467478
Assert.IsTrue (b.Clean (proj), "Clean should have succeeded.");
468479
}
469480
}

src/Xamarin.Android.Build.Tasks/Xamarin.Android.Common.targets

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!--
1+
<!--
22
***********************************************************************************************
33
Xamarin.Android.Common.targets
44
@@ -2307,7 +2307,7 @@ because xbuild doesn't support framework reference assemblies.
23072307

23082308
<Target Name="_ConvertCustomView"
23092309
Condition="Exists('$(_CustomViewMapFile)')"
2310-
Inputs="$(_CustomViewMapFile);$(_AcwMapFile)"
2310+
Inputs="$(_CustomViewMapFile);$(_AcwMapFile);@(_AndroidResourceDest);@(_LibraryResourceDirectoryStamps)"
23112311
Outputs="$(_AndroidStampDirectory)_ConvertCustomView.stamp">
23122312
<ConvertCustomView
23132313
CustomViewMapFile="$(_CustomViewMapFile)"

0 commit comments

Comments
 (0)