Skip to content

Commit 301caff

Browse files
committed
[Xamarin.Android.Build.Tasks] Wrong AndroidManifest.xml packaged to the APK while using binding library
Fixes #4804 We were overwriting the AndroidManifest.xml file in the apk with ones from Support Libraries. This manifests itself with the following error ``` Failed to parse APK info: failed to parse AndroidManifest.xml, error: %!s() deploy failed, error: failed to get apk infos, output: W/ResourceType( 5266): Bad XML block: ```
1 parent 77464dc commit 301caff

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#### Wrong AndroidManifest.xml packaged to the APK while using binding library
2+
3+
* [GitHub 4812][0]: We were overwriting the AndroidManifest.xml file
4+
in the apk with ones from Support Libraries. This manifests itself
5+
with the following error
6+
7+
```
8+
Failed to parse APK info: failed to parse AndroidManifest.xml, error: %!s()
9+
deploy failed, error: failed to get apk infos, output: W/ResourceType( 5266): Bad XML block:
10+
```
11+
12+
13+
[0]: https://github.com/xamarin/xamarin-android/pull/4812

src/Xamarin.Android.Build.Tasks/Tasks/BuildApk.cs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public class BuildApk : AndroidTask
2828

2929
[Required]
3030
public string ApkInputPath { get; set; }
31-
31+
3232
[Required]
3333
public string ApkOutputPath { get; set; }
3434

@@ -101,7 +101,7 @@ bool _Debug {
101101
}
102102

103103
SequencePointsMode sequencePointsMode = SequencePointsMode.None;
104-
104+
105105
public ITaskItem[] LibraryProjectJars { get; set; }
106106
string [] uncompressedFileExtensions;
107107

@@ -241,6 +241,10 @@ void ExecuteWithAbi (string [] supportedAbis, string apkInputPath, string apkOut
241241
Log.LogDebugMessage ($"Skipping {path} as the archive file is up to date.");
242242
continue;
243243
}
244+
if (apk.Archive.Any (e => e.FullName == path)) {
245+
Log.LogMessage ("Warning: failed to add jar entry {0} from {1}: the same file already exists in the apk", name, Path.GetFileName (jarFile));
246+
continue;
247+
}
244248
byte [] data;
245249
using (var d = new MemoryStream ()) {
246250
jarItem.Extract (d);
@@ -256,7 +260,7 @@ void ExecuteWithAbi (string [] supportedAbis, string apkInputPath, string apkOut
256260
count = 0;
257261
}
258262
}
259-
// Clean up Removed files.
263+
// Clean up Removed files.
260264
foreach (var entry in existingEntries) {
261265
Log.LogDebugMessage ($"Removing {entry} as it is not longer required.");
262266
apk.Archive.DeleteEntry (entry);
@@ -296,7 +300,7 @@ public override bool RunTask ()
296300
var apk = Path.GetFileNameWithoutExtension (ApkOutputPath);
297301
ExecuteWithAbi (new [] { abi }, String.Format ("{0}-{1}", ApkInputPath, abi),
298302
Path.Combine (path, String.Format ("{0}-{1}.apk", apk, abi)),
299-
debug, compress, compressedAssembliesInfo);
303+
debug, compress, compressedAssembliesInfo);
300304
outputFiles.Add (Path.Combine (path, String.Format ("{0}-{1}.apk", apk, abi)));
301305
}
302306
}
@@ -548,7 +552,7 @@ string GetNativeLibraryAbi (ITaskItem lib)
548552
{
549553
// If Abi is explicitly specified, simply return it.
550554
var lib_abi = MonoAndroidHelper.GetNativeLibraryAbi (lib);
551-
555+
552556
if (string.IsNullOrWhiteSpace (lib_abi)) {
553557
Log.LogCodedError ("XA4301", lib.ItemSpec, 0, Properties.Resources.XA4301_ABI, lib.ItemSpec);
554558
return null;

0 commit comments

Comments
 (0)