Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AndroidManifest.xml Build errors using VS Mac, Xamarin Forms Android #6385

Closed
yetibyte opened this issue Oct 12, 2021 · 11 comments
Closed

AndroidManifest.xml Build errors using VS Mac, Xamarin Forms Android #6385

yetibyte opened this issue Oct 12, 2021 · 11 comments
Assignees
Labels
Area: App+Library Build Issues when building Library projects or Application projects. need-info Issues that need more information from the author.

Comments

@yetibyte
Copy link

yetibyte commented Oct 12, 2021

Strange problem with Manifest Merger, Visual Studio Mac, Xamarin Forms (5.0.0.2125), Android project, SDK 29 to 30. Problem initiated during an aborted simulator build which generated the error below, indicating the xml structure wasn't closed; line 35, column 11 being was the last line and character of the Properties/AndroidManifest.xml.

/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(3,3): Error AMM0000: Error: org.xml.sax.SAXParseException; lineNumber: 35; columnNumber: 11; XML document structures must start and end within the same entity. (AMM0000)

So, I checked the AndroidManifest.xml, changed a few things and now the obj/debug/AndroidManifest.xml is created and looks right, however, the build errors remain the same.

Subsequent complete rewrites and edits of the Properties/AndroidManifest.xml file have only 2 outcomes:

  1. Entering an erroneous xml format will generate the appropriate errors describing the error = good.
  2. Entering a correct xml format, with any combination of entries, lines and characters will generate a correct obj/debug/AndroidManifest.xml file with the the correct Properties/AndroidManifest.xml content. However, the original build errors stay, with the " line 35, column 11 being was the last line and character of the Properties/AndroidManifest.xml." error.

So, is something cached somewhere?

Have tried quite few things including:

  • cleaning, rebuilding and many combinations
  • removing obj and bin
  • removing/adding declarations in the AndroidManifest.xml
  • using different AndroidManifest.xml files
  • deleting AndroidManifest.xml and running
  • restoring from cloud older a version of solutions
  • commenting out Activity declaration on MainActivity
  • reinstall of VS for Mac

Steps to Reproduce

  1. use this AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.mycompany.myapp" android:versionCode="21" android:versionName="1.21">
<uses-sdk android:minSdkVersion="29" android:targetSdkVersion="30" />
<application android:label="Myapp" android:icon="@mipmap/ic_launcher" android:supportsRtl="true" />
</manifest>
  1. Build project
  2. Get this obj/debug/AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<!--
    This code was generated by a tool.
    It was generated from /Users/AUser/Projects/Myapp/Myapp.Android/Properties/AndroidManifest.xml
    Changes to this file may cause incorrect behavior and will be lost if
    the contents are regenerated.
    -->
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.mycompany.myapp" android:versionCode="21" android:versionName="1.21">
  <uses-sdk android:minSdkVersion="29" android:targetSdkVersion="30" />
  <uses-permission android:name="android.permission.INTERNET" />
  <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
  <application android:label="Myapp" android:icon="@mipmap/ic_launcher" android:supportsRtl="true" android:debuggable="true" android:name="android.app.Application" android:allowBackup="true" android:extractNativeLibs="true">
    <uses-library android:name="org.apache.http.legacy" android:required="false" />
    <activity android:configChanges="orientation|screenSize" android:icon="@mipmap/ic_launcher" android:label="Myapp" android:screenOrientation="fullSensor" android:theme="@style/MainTheme" android:name="crc6426360a96944063ab.MainActivity" />
    <activity android:noHistory="true" android:theme="@style/MyTheme2.Splash" android:name="crc6426360a96944063ab.SplashActivity">
      <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
      </intent-filter>
    </activity>
    <service android:name="crc64396a3fe5f8138e3f.KeepAliveService" />
    <receiver android:enabled="true" android:exported="false" android:label="Essentials Battery Broadcast Receiver" android:name="crc64a0e0a82d0db9a07d.BatteryBroadcastReceiver" />
    <receiver android:enabled="true" android:exported="false" android:label="Essentials Energy Saver Broadcast Receiver" android:name="crc64a0e0a82d0db9a07d.EnergySaverBroadcastReceiver" />
    <receiver android:enabled="true" android:exported="false" android:label="Essentials Connectivity Broadcast Receiver" android:name="crc64a0e0a82d0db9a07d.ConnectivityBroadcastReceiver" />
    <activity android:configChanges="orientation|screenSize" android:name="crc64a0e0a82d0db9a07d.IntermediateActivity" />
    <provider android:authorities="com.mycompany.myapp.fileProvider" android:exported="false" android:grantUriPermissions="true" android:name="xamarin.essentials.fileProvider">
      <meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/xamarin_essentials_fileprovider_file_paths" />
    </provider>
    <activity android:configChanges="orientation|screenSize" android:name="crc64a0e0a82d0db9a07d.WebAuthenticatorIntermediateActivity" />
    <receiver android:enabled="true" android:exported="false" android:name="crc643f46942d9dd1fff9.PowerSaveModeBroadcastReceiver" />
    <provider android:name="mono.MonoRuntimeProvider" android:exported="false" android:initOrder="1999999999" android:authorities="com.mycompany.myapp.mono.MonoRuntimeProvider.__mono_init__" />
  </application>
</manifest>

Expected Behavior

Project builds with no errors

Actual Behavior

/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(3,3): Error AMM0000: Error: Exception while merging manifests (AMM0000) (Myapp.Android)

/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(3,3): Error AMM0000: Error: org.xml.sax.SAXParseException; lineNumber: 35; columnNumber: 11; XML document structures must start and end within the same entity. (AMM0000) (Myapp.Android)

Environment

=== Visual Studio Community 2019 for Mac ===

Version 8.10.10 (build 8)
Installation UUID: ea6c1138-8c66-4394-a9ad-bbe500f82e4b
	GTK+ 2.24.23 (Raleigh theme)
	Xamarin.Mac 6.18.0.23 (d16-6 / 088c73638)

	Package version: 612000140

=== Mono Framework MDK ===

Runtime:
	Mono 6.12.0.140 (2020-02/51d876a041e) (64-bit)
	Package version: 612000140

=== Xamarin Designer ===

Version: 16.10.0.119
Hash: 36a2d986f
Branch: remotes/origin/d16-10
Build date: 2021-06-02 19:41:34 UTC

=== Roslyn (Language Service) ===

3.10.0-4.21269.26+029847714208ebe49668667c60ea5b0a294e0fcb

=== NuGet ===

Version: 5.9.0.7134

=== .NET Core SDK ===

SDK: /usr/local/share/dotnet/sdk/5.0.401/Sdks
SDK Versions:
	5.0.401
	5.0.400
	5.0.302
	5.0.301
	5.0.203
	5.0.202
	5.0.201
	5.0.103
	5.0.102
	5.0.101
	5.0.100
	3.1.413
	3.1.412
	3.1.411
	3.1.410
	3.1.409
	3.1.408
	3.1.407
	3.1.406
	3.1.405
	3.1.404
	3.1.403
	3.1.402
	3.1.401
	3.1.302
	3.1.301
	3.1.300
	3.1.200
	3.1.101
	3.1.100
	3.0.101
	3.0.100
	2.1.701
	2.1.700
	2.1.505
	2.1.504
	2.1.302
	2.1.4
	2.0.0
MSBuild SDKs: /Applications/Visual Studio.app/Contents/Resources/lib/monodevelop/bin/MSBuild/Current/bin/Sdks

=== .NET Core Runtime ===

Runtime: /usr/local/share/dotnet/dotnet
Runtime Versions:
	5.0.10
	5.0.9
	5.0.8
	5.0.7
	5.0.6
	5.0.5
	5.0.4
	5.0.3
	5.0.2
	5.0.1
	5.0.0
	3.1.19
	3.1.18
	3.1.17
	3.1.16
	3.1.15
	3.1.14
	3.1.13
	3.1.12
	3.1.11
	3.1.10
	3.1.9
	3.1.8
	3.1.7
	3.1.6
	3.1.5
	3.1.4
	3.1.2
	3.1.1
	3.1.0
	3.0.1
	3.0.0
	2.1.23
	2.1.22
	2.1.21
	2.1.20
	2.1.19
	2.1.18
	2.1.16
	2.1.15
	2.1.14
	2.1.13
	2.1.12
	2.1.11
	2.1.9
	2.1.8
	2.1.2
	2.0.5
	2.0.0

=== .NET Core 3.1 SDK ===

SDK: 3.1.413

=== Xamarin.Profiler ===

Version: 1.6.15.68
Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler

=== Updater ===

Version: 11

=== Xamarin.Android ===

Version: 11.3.0.4 (Visual Studio Community)
Commit: xamarin-android/d16-10/ae14caf
Android SDK: /Users/AUser/Library/Developer/Xamarin/android-sdk-macosx
	Supported Android versions:
		None installed

SDK Tools Version: 26.1.1
SDK Platform Tools Version: 30.0.4
SDK Build Tools Version: 30.0.2

Build Information: 
Mono: b4a3858
Java.Interop: xamarin/java.interop/d16-10@f39db25
ProGuard: Guardsquare/proguard/v7.0.1@912d149
SQLite: xamarin/sqlite/3.35.4@85460d3
Xamarin.Android Tools: xamarin/xamarin-android-tools/d16-10@c5732a0

=== Microsoft OpenJDK for Mobile ===

Java SDK: /Users/AUser/Library/Developer/Xamarin/jdk/microsoft_dist_openjdk_8.0.25
1.8.0-25
Android Designer EPL code available here:
https://github.com/xamarin/AndroidDesigner.EPL

=== Android SDK Manager ===

Version: 16.10.0.13
Hash: 1b81df5
Branch: remotes/origin/d16-10
Build date: 2021-09-21 02:30:50 UTC

=== Android Device Manager ===

Version: 16.10.0.15
Hash: 89dcc0b
Branch: remotes/origin/d16-10
Build date: 2021-09-21 02:31:08 UTC

=== Apple Developer Tools ===

Xcode 13.0 (19234)
Build 13A233

=== Xamarin.Mac ===

Xamarin.Mac not installed. Can't find /Library/Frameworks/Xamarin.Mac.framework/Versions/Current/Version.

=== Xamarin.iOS ===

Version: 15.0.0.6 (Visual Studio Community)
Hash: 2771277e0
Branch: xcode13-ios
Build date: 2021-09-23 10:36:08-0400

=== Build Information ===

Release ID: 810100008
Git revision: a3ff4b6e658e1f94623e1f3ed34ca94ed4fe78d8
Build date: 2021-09-23 19:50:51-04
Build branch: release-8.10

=== Operating System ===

Mac OS X 10.16.0
Darwin 20.6.0 Darwin Kernel Version 20.6.0
    Mon Aug 30 06:12:21 PDT 2021
    root:xnu-7195.141.6~3/RELEASE_X86_64 x86_64


Build Logs

Example Project (If Possible)

@chamons chamons transferred this issue from xamarin/xamarin-macios Oct 12, 2021
@jpobst jpobst added Area: App+Library Build Issues when building Library projects or Application projects. needs-triage Issues that need to be assigned. labels Oct 12, 2021
@dellis1972 dellis1972 added need-info Issues that need more information from the author. and removed needs-triage Issues that need to be assigned. labels Oct 12, 2021
@dellis1972
Copy link
Contributor

@yetibyte can you provide a diagnostic build log which contains the error?
There is a fair chance it might be a manifest file which is being pulled in from a ProjectReference or PackageReference which is causing the problem.

@jonpryor
Copy link
Member

I suspect part of the problem is in (1) "use this AndroidManifest.xml":

 <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.mycompany.myapp" android:versionCode="21" android:versionName="1.21">
…

Note the leading space. This isn't valid; "everything" doesn't like it.

% xmllint x.xml
x.xml:1: parser error : XML declaration allowed only at the start of the document
 <?xml version="1.0" ?>
      ^
var d = XDocument.Parse("x.xml");                                                                                                                                                                             
// System.Xml.XmlException: Data at the root level is invalid. Line 1, position 1.                                                                                                                                 

I haven't tried using a Java XML parser, but it wouldn't surprise me that invalid XML was responsible for the reported error message:

org.xml.sax.SAXParseException; lineNumber: 35; columnNumber: 11; XML document structures must start and end within the same entity.

Does Properties/AndroidManifest.xml start with a space? Is it valid XML?

@jonpryor
Copy link
Member

That said, if I change e.g. samples/HelloWorld/Properties/AndroidManifest.xml to contain leading whitespace, I get a different error:

% ../../bin/Debug/bin/xabuild /t:SignAndroidPackage /v:diag HelloWorld.csproj
…
…/Xamarin.Android.Common.targets(514,3): error XAGAP7000: System.Xml.XmlException: Unexpected XML declaration. The XML declaration must be the first node in the document, and no white space characters are allowed to appear before it. Line 1, position 4. 

@yetibyte
Copy link
Author

Hello jonpryor, thanks for comments, the leading space is not present in the files, is just my copy paste error into this issue description, apologies.

@yetibyte
Copy link
Author

yetibyte commented Oct 14, 2021

Hello dellis1972, thanks for you help, have added the build log here with full diagnostic output.

Build Log.txt

@dellis1972
Copy link
Contributor

@yetibyte could you also upload the following file obj/Debug/android/manifestmerger.rsp It will have the command line arguments that are being passed.

@dellis1972
Copy link
Contributor

@yetibyte actually, you might not be able to. I that file gets deleted after the task executes.

@yetibyte
Copy link
Author

Hello @dellis1972, this bug still remains, am trying to find if there is an equivalent manifest merge view in VS mac similar to the Android Studio function developer.android.com/studio/build/manage-manifests?
Android Studio provides very detailed information about the inputs, outputs and decisions made by the merging algorithm.

@dellis1972
Copy link
Contributor

@yetibyte

There is not equivalent manifest merge view in VS Mac I'm afraid.
I'll look and see if there are additional options we can pass to the tool to output diagnostics.

Looking at the build log you provided, in addition to your AndroidManifest.xml the following are all the additional files which
will get passed to the tool.

      ManifestDocuments: 
        obj/Debug/lp/135/jl/AndroidManifest.xml
        obj/Debug/lp/61/jl/AndroidManifest.xml
        obj/Debug/lp/95/jl/AndroidManifest.xml
        obj/Debug/lp/132/jl/AndroidManifest.xml
        obj/Debug/lp/92/jl/AndroidManifest.xml
        obj/Debug/lp/66/jl/AndroidManifest.xml
        obj/Debug/lp/104/jl/AndroidManifest.xml
        obj/Debug/lp/103/jl/AndroidManifest.xml
        obj/Debug/lp/102/jl/AndroidManifest.xml
        obj/Debug/lp/105/jl/AndroidManifest.xml
        obj/Debug/lp/133/jl/AndroidManifest.xml
        obj/Debug/lp/67/jl/AndroidManifest.xml
        obj/Debug/lp/93/jl/AndroidManifest.xml
        obj/Debug/lp/134/jl/AndroidManifest.xml
        obj/Debug/lp/94/jl/AndroidManifest.xml
        obj/Debug/lp/142/jl/AndroidManifest.xml
        obj/Debug/lp/129/jl/AndroidManifest.xml
        obj/Debug/lp/89/jl/AndroidManifest.xml
        obj/Debug/lp/116/jl/AndroidManifest.xml
        obj/Debug/lp/111/jl/AndroidManifest.xml
        obj/Debug/lp/73/jl/AndroidManifest.xml
        obj/Debug/lp/118/jl/AndroidManifest.xml
        obj/Debug/lp/87/jl/AndroidManifest.xml
        obj/Debug/lp/127/jl/AndroidManifest.xml
        obj/Debug/lp/80/jl/AndroidManifest.xml
        obj/Debug/lp/74/jl/AndroidManifest.xml
        obj/Debug/lp/120/jl/AndroidManifest.xml
        obj/Debug/lp/143/jl/AndroidManifest.xml
        obj/Debug/lp/1/jl/AndroidManifest.xml
        obj/Debug/lp/75/jl/AndroidManifest.xml
        obj/Debug/lp/81/jl/AndroidManifest.xml
        obj/Debug/lp/121/jl/AndroidManifest.xml
        obj/Debug/lp/119/jl/AndroidManifest.xml
        obj/Debug/lp/86/jl/AndroidManifest.xml
        obj/Debug/lp/72/jl/AndroidManifest.xml
        obj/Debug/lp/126/jl/AndroidManifest.xml
        obj/Debug/lp/110/jl/AndroidManifest.xml
        obj/Debug/lp/128/jl/AndroidManifest.xml
        obj/Debug/lp/88/jl/AndroidManifest.xml
        obj/Debug/lp/117/jl/AndroidManifest.xml
        obj/Debug/lp/131/jl/AndroidManifest.xml
        obj/Debug/lp/91/jl/AndroidManifest.xml
        obj/Debug/lp/65/jl/AndroidManifest.xml
        obj/Debug/lp/136/jl/AndroidManifest.xml
        obj/Debug/lp/96/jl/AndroidManifest.xml
        obj/Debug/lp/109/jl/AndroidManifest.xml
        obj/Debug/lp/100/jl/AndroidManifest.xml
        obj/Debug/lp/107/jl/AndroidManifest.xml
        obj/Debug/lp/98/jl/AndroidManifest.xml
        obj/Debug/lp/138/jl/AndroidManifest.xml
        obj/Debug/lp/106/jl/AndroidManifest.xml
        obj/Debug/lp/99/jl/AndroidManifest.xml
        obj/Debug/lp/139/jl/AndroidManifest.xml
        obj/Debug/lp/101/jl/AndroidManifest.xml
        obj/Debug/lp/137/jl/AndroidManifest.xml
        obj/Debug/lp/97/jl/AndroidManifest.xml
        obj/Debug/lp/108/jl/AndroidManifest.xml
        obj/Debug/lp/63/jl/AndroidManifest.xml
        obj/Debug/lp/130/jl/AndroidManifest.xml
        obj/Debug/lp/64/jl/AndroidManifest.xml
        obj/Debug/lp/90/jl/AndroidManifest.xml
        obj/Debug/lp/79/jl/AndroidManifest.xml
        obj/Debug/lp/112/jl/AndroidManifest.xml
        obj/Debug/lp/115/jl/AndroidManifest.xml
        obj/Debug/lp/83/jl/AndroidManifest.xml
        obj/Debug/lp/77/jl/AndroidManifest.xml
        obj/Debug/lp/123/jl/AndroidManifest.xml
        obj/Debug/lp/84/jl/AndroidManifest.xml
        obj/Debug/lp/124/jl/AndroidManifest.xml
        obj/Debug/lp/141/jl/AndroidManifest.xml
        obj/Debug/lp/85/jl/AndroidManifest.xml
        obj/Debug/lp/125/jl/AndroidManifest.xml
        obj/Debug/lp/76/jl/AndroidManifest.xml
        obj/Debug/lp/82/jl/AndroidManifest.xml
        obj/Debug/lp/122/jl/AndroidManifest.xml
        obj/Debug/lp/114/jl/AndroidManifest.xml
        obj/Debug/lp/113/jl/AndroidManifest.xml
        obj/Debug/lp/78/jl/AndroidManifest.xml
        obj/Debug/lp/140/jl/AndroidManifest.xml

If you want to know which library or project these files come from there is a map.cache file in obj/Debug/lp. Each line maps to the folder to which the data was extracted (we do this to get around max path issues on windows).
So line 0 (its zero based) will be obj/Debug/lp/0/jl/AndroidManifest.xml. It will allow you to back track which folder is from nuget files or aar's.

I suspect one of these files has got a problem which is causing manifest merger to fail.

@yetibyte
Copy link
Author

@dellis1972
Thanks for the information, the problem was in this file

obj/Debug/lp/142/jl/AndroidManifest.xml

Listing below, it is missing the final ">" on line 35, column 11.
Looking through the map.cache file, line 141 was playservicesmeasurement-19.0.1.aar.
Hence, I excluded the Firebase Analytics library and now the project builds fine.

Have yet to find out why the missing character in the Firebase library, but will do.

So thanks again.

For future iterations, I think someone needs to add a few lines to the merger scripts to output the directory/filename of the problematic AndroidManifest.xml file. In my case, I had 140+ files to search through and was originally misdirected due to an unfortunate coincidence that the error reported on line 35, column 11 exactly matched the length of my properties/AndroidManifest.xml file.

`

<uses-sdk android:minSdkVersion="16" />

<!-- Required permission for App measurement to run. -->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="com.google.android.finsky.permission.BIND_GET_INSTALL_REFERRER_SERVICE" />

<application>
    <receiver android:name="com.google.android.gms.measurement.AppMeasurementReceiver" android:enabled="true" android:exported="false">
    </receiver>

    <service android:name="com.google.android.gms.measurement.AppMeasurementService" android:enabled="true" android:exported="false" />
    <service android:name="com.google.android.gms.measurement.AppMeasurementJobService" android:enabled="true" android:exported="false" android:permission="android.permission.BIND_JOB_SERVICE" />
</application>

</manifest
`

@dellis1972
Copy link
Contributor

Glad you found the issue.

We are going to add #6397 which will let people gather additional output which will help track down the issue.

@ghost ghost locked as resolved and limited conversation to collaborators Jun 2, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Area: App+Library Build Issues when building Library projects or Application projects. need-info Issues that need more information from the author.
Projects
None yet
Development

No branches or pull requests

5 participants