Skip to content

Commit

Permalink
[Xamarin.Android.Build.Tasks] Library project C# changes & Rebuilds (d…
Browse files Browse the repository at this point in the history
…otnet#764)

Fixes: https://bugzilla.xamarin.com/show_bug.cgi?id=58865

Consider a project with an `App.csproj` and a referenced
`Lib.csproj`. Not all changes to C# sources within `Lib.csproj`
should require rebuilding and redeploying the `.apk` when
Fast Deployment is enabled; only those that result in changes
to Java Callable Wrappers should require rebuilding and
redeploying the `.apk`.

Unfortunately, that wasn't the case: *any* change to `Lib.csproj`
would result rebuilding and redeploying the `.apk`, because
`AndroidManifest.xml` was constantly being modified, which would
cause the `_CompileToDalvikWithDx` target to be invoked, resulting
in a `.apk` rebuild + redeploy.

The item

	<meta-data android:name="android.support.VERSION" android:value="25.4.0" />

was constantly being duplicated in the manifest. As a result it
was always newer and was triggering a change of build targets.

So we need to double check we are NOT adding 100% duplicate
values to the manifest.
  • Loading branch information
dellis1972 authored and jonpryor committed Sep 11, 2017
1 parent 318dd7e commit d079a42
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,8 @@ public void MergeLibraryManifest ()
android:authorities='${applicationId}.FacebookInitProvider'
android:name='.internal.FacebookInitProvider'
android:exported='false' />
<meta-data android:name='android.support.VERSION' android:value='25.4.0' />
<meta-data android:name='android.support.VERSION' android:value='25.4.0' />
</application>
</manifest>
", encoding: System.Text.Encoding.UTF8);
Expand Down Expand Up @@ -522,6 +524,8 @@ public void MergeLibraryManifest ()
"${applicationId}.FacebookInitProvider was not replaced with com.xamarin.manifest.FacebookInitProvider");
Assert.IsTrue (manifest.Contains ("com.xamarin.test.internal.FacebookInitProvider"),
".internal.FacebookInitProvider was not replaced with com.xamarin.test.internal.FacebookInitProvider");
Assert.AreEqual (manifest.IndexOf ("meta-data", StringComparison.OrdinalIgnoreCase),
manifest.LastIndexOf ("meta-data", StringComparison.OrdinalIgnoreCase), "There should be only one meta-data element");
}
}
}
Expand Down
11 changes: 11 additions & 0 deletions src/Xamarin.Android.Build.Tasks/Utilities/ManifestDocument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,16 @@ void MergeLibraryManifest (string mergedManifest)
}
}

void RemoveDuplicateElements ()
{
var duplicates = doc.Descendants ()
.GroupBy (x => x.ToFullString ())
.SelectMany (x => x.Skip (1));
foreach (var duplicate in duplicates)
duplicate.Remove ();

}

IEnumerable<XNode> FixupNameElements(string packageName, IEnumerable<XNode> nodes)
{
foreach (var element in nodes.Select ( x => x as XElement).Where (x => x != null && ManifestAttributeFixups.ContainsKey (x.Name.LocalName))) {
Expand Down Expand Up @@ -838,6 +848,7 @@ public void Save (string filename)

public void Save (System.IO.TextWriter stream)
{
RemoveDuplicateElements ();
var ms = new MemoryStream ();
doc.Save (ms);
ms.Flush ();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ public static string[] GetPaths (this XDocument doc, params string[] paths)
e = e.Elements (p);
return e.Select (p => p.Value).ToArray ();
}

public static string ToFullString (this XElement element)
{
return element.ToString (SaveOptions.DisableFormatting);
}
}
}

0 comments on commit d079a42

Please sign in to comment.