Xamarin.forms: [Bug] unexpected element <uses-permission> found in <manifest><application>.

Created on 18 Sep 2019  路  13Comments  路  Source: xamarin/Xamarin.Forms

Description

I am working and continuing on a Xamarin.Forms project from someone one. I am getting a weird error while building the project. I am using Visual Studio Pro 2019 Preview 3.0 by the way on Windows 10 Pro.

In my Android project, The error was
unexpected element <uses-permission> found in <manifest><application>

I tried moving that node outside the node but every time I rebuild the project, it goes back to its old parent node (the node)

The weird part is, when I use Visual Studio 2019 Professional version 16.2.5, it compiles just fine and I'm able to run the project on my android device.

I am also not sure, why these <uses-feature> node are in <application> node and at the end of manifest files? Why can't they just be in one place..

How do I fix this?

Steps to Reproduce

  1. I am not really sure ----

Expected Behavior

Should be able to compile and run the android application

Actual Behavior

It throws this error 'unexpected element <uses-permission> found in <manifest><application>'

Basic Information

  • Version with issue:
    --- Visual Studio Pro 2019 Prev 3.0
    --- Xamarin.Forms 3.3
  • Last known good version:
    --- Visual Studio Pro 2019 ver 16.2.5
    --- Xamarin.Forms 3.3 on the non Prev version of VSPro2019
  • IDE: Visual Studio Pro 2019
  • Platform Target Frameworks:

    • Android: probably all, my test device is Android 8.1 API 27

  • Android Support Library Version:
  • Nuget Packages:
  • Affected Devices: Both emu and actual devices

Screenshots


image

Reproduction Link

none --

unverified bug

Most helpful comment

I am facing the same issue, how did you fix this?

I was editing a wrong manifest file. The manifest file I was editing was in the OBJ/~/~/~ folder

checkout which file you are editing by hovering onto the tab.

You should be editing the AndroidManifest.xml file in Android project Properties folder

All 13 comments

just updated to the latest XF version ...

I need to reopen this again because even after updating to the latest version of XF and these packages here.

Xamarin.Forms (4.2.0.778463)

Xamarin.Android.Support.Animated.Vector.Drawable (28.0.0.1)
Xamarin.Android.Support.v4 (28.0.0.1)
Xamarin.Android.Support.v7.AppCompat (28.0.0.1)
Xamarin.Android.Support.v7.CardView (28.0.0.1)
Xamarin.Android.Support.v7.MediaRouter (28.0.0.1)
Xamarin.Android.Support.v7.Palette (28.0.0.1)
Xamarin.Android.Support.Vector.Drawable (28.0.0.1)
Xamarin.Android.Support.Annotations (28.0.0.1)
Xamarin.Android.Support.AsyncLayoutInflater (28.0.0.1)
Xamarin.Android.Support.Collections (28.0.0.1)
Xamarin.Android.Support.Compat (28.0.0.1)
Xamarin.Android.Support.CoordinaterLayout (28.0.0.1)
Xamarin.Android.Support.Core.UI (28.0.0.1)
Xamarin.Android.Support.Core.Utils (28.0.0.1)
Xamarin.Android.Support.CursorAdapter (28.0.0.1)
Xamarin.Android.Support.CustomTabs (28.0.0.1)
Xamarin.Android.Support.CustomView (28.0.0.1)
Xamarin.Android.Support.Design (28.0.0.1)
Xamarin.Android.Support.DocumentFile (28.0.0.1)
Xamarin.Android.Support.DrawerLayout (28.0.0.1)
Xamarin.Android.Support.Fragment (28.0.0.1)
Xamarin.Android.Support.Interpolator (28.0.0.1)
Xamarin.Android.Support.Loader (28.0.0.1)
Xamarin.Android.Support.LocalBroadcastManager (28.0.0.1)
Xamarin.Android.Support.Media.Compat (28.0.0.1)
Xamarin.Android.Support.Print (28.0.0.1)
Xamarin.Android.Support.SlidingPaneLayout (28.0.0.1)
Xamarin.Android.Support.SwipeRefreshLayout (28.0.0.1)
Xamarin.Android.Support.Transition (28.0.0.1)
Xamarin.Android.Support.v7.RecyclerView (28.0.0.1)
Xamarin.Android.Support.VersionedParcelable (28.0.0.1)
Xamarin.Android.Support.ViewPager (28.0.0.1)

I still get that issue. PLease help

Here's how the AndroidManifest.xml looks like

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionName="1.0.0.67-dev" package="com.TheAppName.sp" android:installLocation="preferExternal" android:versionCode="19">
<uses-sdk android:minSdkVersion="21" android:targetSdkVersion="28" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.CAPTURE_VIDEO_OUTPUT" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
<uses-permission android:name="android.permission.ACCESS_MOCK_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.READ_CALENDAR" />
<uses-permission android:name="android.permission.WRITE_CALENDAR" />
<permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-feature android:name="android.hardware.location" android:required="false" />
<uses-feature android:name="android.hardware.location.gps" android:required="false" />
<uses-feature android:name="android.hardware.location.network" android:required="false" />
<uses-feature android:name="android.hardware.camera" android:required="false" />
<uses-feature android:name="android.hardware.camera.autofocus" android:required="false" />
<application android:label="TheAppName Pro" android:icon="@mipmap/ic_launcher" android:name="md5XXXXXXXXXXXXX.MainApplication" android:allowBackup="true" android:debuggable="true">
<provider android:name="android.support.v4.content.FileProvider" android:authorities="com.TheAppName.sp.fileprovider" android:exported="false" android:grantUriPermissions="true">
<meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/file_paths"></meta-data>
</provider>
<!--Facebook Api Access -->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<meta-data android:name="com.facebook.sdk.ApplicationId" android:value="@string/facebook_app_id" />
<activity android:name="com.facebook.FacebookActivity" android:configChanges="keyboard|keyboardHidden|screenLayout|screenSize|orientation" android:theme="@android:style/Theme.Translucent.NoTitleBar" android:label="@string/app_name" />
<provider android:authorities="com.facebook.app.FacebookContentProvider" android:name="com.facebook.FacebookContentProvider" android:exported="true" />
<!--push notification-->
<receiver android:name="com.google.firebase.iid.FirebaseInstanceIdInternalReceiver" android:exported="false" />
<receiver android:name="com.google.firebase.iid.FirebaseInstanceIdReceiver" android:exported="true" android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="com.TheAppName.sp" />
</intent-filter>
</receiver>
<meta-data android:name="com.google.firebase.messaging.default_notification_icon" android:resource="@drawable/icon" />
<meta-data android:name="com.facebook.sdk.ApplicationName" android:value="@string/app_name" />
<activity android:label="FacebookSignInActivity" android:theme="@android:style/Theme.Translucent.NoTitleBar" android:name="md5XXXXXXXXXXXXX.FacebookSignInActivity" />
<activity android:label="GoogleSignInActivity" android:theme="@android:style/Theme.Translucent.NoTitleBar" android:name="md5XXXXXXXXXXXXX.GoogleSignInActivity" />
<activity android:configChanges="screenSize" android:icon="@mipmap/ic_launcher" android:label="TheAppName Pro" android:screenOrientation="portrait" android:theme="@style/MainTheme" android:name="md5XXXXXXXXXXXXX.MainActivity" />
<activity android:configChanges="screenSize" android:icon="@mipmap/ic_launcher" android:label="TheAppName Pro" android:screenOrientation="portrait" android:theme="@style/SplashTheme" android:name="md5XXXXXXXXXXXXX.SplashScreen">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:label="Web Authenticator" android:name="md5XXXXXXXXXXXXX.FormAuthenticatorActivity" />
<activity android:label="Web Authenticator" android:name="md5XXXXXXXXXXXXX.WebAuthenticatorActivity" />
<activity android:label="Web Authenticator Native Broswer" android:launchMode="singleTop" android:name="md5XXXXXXXXXXXXX.WebAuthenticatorNativeBrowserActivity" />
<activity android:name="com.microsoft.windowsazure.mobileservices.authentication.RedirectUrlActivity" />
<service android:name="md5XXXXXXXXXXXXX.PNFirebaseIIDService">
<intent-filter>
<action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
</intent-filter>
</service>
<service android:name="md5XXXXXXXXXXXXX.PNFirebaseMessagingService">
<intent-filter>
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
<receiver android:name="md5XXXXXXXXXXXXX.PushNotificationActionReceiver" />
<receiver android:name="md5XXXXXXXXXXXXX.PushNotificationDeletedReceiver" />
<activity android:configChanges="orientation|screenSize" android:name="md54cd65ac53ae710bff80022afc423e0f3.MediaPickerActivity" />
<service android:name="md5dcb6eccdc824e0677ffae8ccdde42930.KeepAliveService" />
<receiver android:enabled="true" android:exported="false" android:label="Essentials Battery Broadcast Receiver" android:name="md5XXXXXXXXXXXXX.BatteryBroadcastReceiver" />
<receiver android:enabled="true" android:exported="false" android:label="Essentials Energy Saver Broadcast Receiver" android:name="md5XXXXXXXXXXXXX.EnergySaverBroadcastReceiver" />
<receiver android:enabled="true" android:exported="false" android:label="Essentials Connectivity Broadcast Receiver" android:name="md5XXXXXXXXXXXXX.ConnectivityBroadcastReceiver" />
<provider android:authorities="com.TheAppName.sp.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>
<receiver android:enabled="true" android:exported="false" android:name="md5XXXXXXXXXXXXX.PowerSaveModeBroadcastReceiver" />
<provider android:name="mono.android.MultiDexLoader" android:exported="false" android:initOrder="1999999999" android:authorities="com.TheAppName.sp.mono.android.MultiDexLoader.__mono_init__" />
<provider android:name="mono.MonoRuntimeProvider" android:exported="false" android:initOrder="1999999998" android:authorities="com.TheAppName.sp.mono.MonoRuntimeProvider.__mono_init__" />
<!--suppress ExportedReceiver-->
<receiver android:name="mono.android.Seppuku">
<intent-filter>
<action android:name="mono.android.intent.action.SEPPUKU" />
<category android:name="mono.android.intent.category.SEPPUKU.com.TheAppName.sp" />
</intent-filter>
</receiver>
<activity android:name="com.microsoft.appcenter.distribute.DeepLinkActivity" android:theme="@android:style/Theme.NoDisplay">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:host="updates" android:path="/" android:scheme="appcenter" />
</intent-filter>
</activity>
<receiver android:name="com.microsoft.appcenter.distribute.DownloadManagerReceiver">
<intent-filter>
<action android:name="android.intent.action.DOWNLOAD_COMPLETE" />
<action android:name="android.intent.action.DOWNLOAD_NOTIFICATION_CLICKED" />
</intent-filter>
</receiver>
<provider android:authorities="com.TheAppName.sp.firebaseinitprovider" android:name="com.google.firebase.provider.FirebaseInitProvider" android:exported="false" android:initOrder="100" />
<receiver android:name="com.google.firebase.iid.FirebaseInstanceIdReceiver" android:exported="true" android:permission="com.google.android.c2dm.permission.SEND">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="com.TheAppName.sp" />
</intent-filter>
</receiver>
<!-- Internal (not exported) receiver used by the app to start its own exported services
without risk of being spoofed. -->
<!-- FirebaseInstanceIdService performs security checks at runtime,
no need for explicit permissions despite exported="true" -->
<service android:name="com.google.firebase.iid.FirebaseInstanceIdService" android:exported="true">
<intent-filter android:priority="-500">
<action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
</intent-filter>
</service>
<!-- FirebaseMessagingService performs security checks at runtime,
no need for explicit permissions despite exported="true" -->
<service android:name="com.google.firebase.messaging.FirebaseMessagingService" android:exported="true">
<intent-filter android:priority="-500">
<action android:name="com.google.firebase.MESSAGING_EVENT" />
</intent-filter>
</service>
<activity android:name="com.google.android.gms.auth.api.signin.internal.SignInHubActivity" android:theme="@android:style/Theme.Translucent.NoTitleBar" android:excludeFromRecents="true" android:exported="false" />
<!--Service handling Google Sign-In user revocation. For apps that do not integrate with
Google Sign-In, this service will never be started.-->
<service android:name="com.google.android.gms.auth.api.signin.RevocationBoundService" android:exported="true" android:permission="com.google.android.gms.auth.api.signin.permission.REVOCATION_NOTIFICATION" />
<activity android:name="com.google.android.gms.common.api.GoogleApiActivity" android:theme="@android:style/Theme.Translucent.NoTitleBar" android:exported="false" />
<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
</application>
<!-- application android:label="@string/app_name">
<meta-data android:name="com.google.android.geo.API_KEY" android:value="AIZASY" />
<meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" />
</application -->
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
<uses-permission android:name="android.permission.DOWNLOAD_WITHOUT_NOTIFICATION" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<permission android:name="com.TheAppName.sp.permission.C2D_MESSAGE" android:protectionLevel="signature" />
<uses-permission android:name="com.TheAppName.sp.permission.C2D_MESSAGE" />
</manifest>

The error is at below application node just after <!--Facebook Api Access -->

I am editing the wrong manifest file.

I am facing the same issue, how did you fix this?

I am facing the same issue, how did you fix this?

I was editing a wrong manifest file. The manifest file I was editing was in the OBJ/~/~/~ folder

checkout which file you are editing by hovering onto the tab.

You should be editing the AndroidManifest.xml file in Android project Properties folder

I was experiencing the same issue after upgrading to latest version of VS2019; fix for me was inside the AndroidManifest.xml (under Properties); move the receiver elements inside the application tag. Was able to successfully build after that. Make sure you are editing the manifest file under the properties folder in Solution Explorer. Double-clicking the error in the Errors pane opens up a copy of the manifest file in the obj folder - which is not what you want.

Yeah I also tried this, however each build makes the AndroidManifest.xml revert back. Not sure what to do.

@dan5602 make sure you are editing the manifest file under the properties folder and not the one that gets generated in the obj folder. Easy mistake to make.

Thanks @JajaHarris and @Nullstr1ng. Making some progress now - can at least build!

Thanks @JajaHarris that helped me as well!

For me, this happened because my original AndroidManifest.xml was broken, but something in previous versions of Visual Studio was compensating for it. So, it was the same AndroidManifest.xml as before, but I had a uses-permission inside the tag, and it should have been outside the application tag. Moving it fixed it, despite the fact that it was working prior to VS 8.3 (Mac).

I had the same issue.
I had to delete the Bin/Obj/.vs folders, update the NuGet packages, change the Target Framework to Android Pie, Rebuild and remove the user-permission tags from the AndroidManifest.xml file under the Properties folder. And then everything was fine.

Was this page helpful?
0 / 5 - 0 ratings