Skip to content

Commit d079a42

Browse files
dellis1972jonpryor
authored andcommitted
[Xamarin.Android.Build.Tasks] Library project C# changes & Rebuilds (dotnet#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.
1 parent 318dd7e commit d079a42

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,8 @@ public void MergeLibraryManifest ()
486486
android:authorities='${applicationId}.FacebookInitProvider'
487487
android:name='.internal.FacebookInitProvider'
488488
android:exported='false' />
489+
<meta-data android:name='android.support.VERSION' android:value='25.4.0' />
490+
<meta-data android:name='android.support.VERSION' android:value='25.4.0' />
489491
</application>
490492
</manifest>
491493
", encoding: System.Text.Encoding.UTF8);
@@ -522,6 +524,8 @@ public void MergeLibraryManifest ()
522524
"${applicationId}.FacebookInitProvider was not replaced with com.xamarin.manifest.FacebookInitProvider");
523525
Assert.IsTrue (manifest.Contains ("com.xamarin.test.internal.FacebookInitProvider"),
524526
".internal.FacebookInitProvider was not replaced with com.xamarin.test.internal.FacebookInitProvider");
527+
Assert.AreEqual (manifest.IndexOf ("meta-data", StringComparison.OrdinalIgnoreCase),
528+
manifest.LastIndexOf ("meta-data", StringComparison.OrdinalIgnoreCase), "There should be only one meta-data element");
525529
}
526530
}
527531
}

src/Xamarin.Android.Build.Tasks/Utilities/ManifestDocument.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,16 @@ void MergeLibraryManifest (string mergedManifest)
401401
}
402402
}
403403

404+
void RemoveDuplicateElements ()
405+
{
406+
var duplicates = doc.Descendants ()
407+
.GroupBy (x => x.ToFullString ())
408+
.SelectMany (x => x.Skip (1));
409+
foreach (var duplicate in duplicates)
410+
duplicate.Remove ();
411+
412+
}
413+
404414
IEnumerable<XNode> FixupNameElements(string packageName, IEnumerable<XNode> nodes)
405415
{
406416
foreach (var element in nodes.Select ( x => x as XElement).Where (x => x != null && ManifestAttributeFixups.ContainsKey (x.Name.LocalName))) {
@@ -838,6 +848,7 @@ public void Save (string filename)
838848

839849
public void Save (System.IO.TextWriter stream)
840850
{
851+
RemoveDuplicateElements ();
841852
var ms = new MemoryStream ();
842853
doc.Save (ms);
843854
ms.Flush ();

src/Xamarin.Android.Build.Tasks/Utilities/XDocumentExtensions.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ public static string[] GetPaths (this XDocument doc, params string[] paths)
2222
e = e.Elements (p);
2323
return e.Select (p => p.Value).ToArray ();
2424
}
25+
26+
public static string ToFullString (this XElement element)
27+
{
28+
return element.ToString (SaveOptions.DisableFormatting);
29+
}
2530
}
2631
}
2732

0 commit comments

Comments
 (0)