Unable to read package name from AndroidManifest.xml

I have errors in the Android manifest file:

Error:Cannot read packageName from C:\Users\brandon\AndroidStudioProjects\MineDodge2\app\src\main\AndroidManifest.xβ€Œβ€‹ml Error:The markup in the document preceding the root element must be well-formed. 

I tried looking at this site, but the answers do not work for me.

 <?xml version="1.0" encoding="utf-8"?> < manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.brandon.MineDodge" > <application android:allowBackup="true" android:icon="@mipmap/redjet" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name="com.example.brandon.MineDodge.MainActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> </activity> <activity android:name="com.example.brandon.MineDodge.Splash" /> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </application> </manifest> 
+13
source share
12 answers

If you are using an old version of the build.grade file, you must remove this code:

 sourceSets { main { manifest.srcFile 'AndroidManifest.xml' java.srcDirs = ['src'] res.srcDirs = ['res'] } } 

Then Build> Clean Project

Note : if you see this code, you are using the old version

+17
source

The error is very simple, and I'm pretty disappointed with the stack community not to find it so far.

 < manifest ... 

should become

 <manifest... 

Basically, remove the extra space. Which causes the following error:

 Error:The markup in the document preceding the root element must be well-formed. 

In addition, the intent filter used for MainActivity should also be used for the second action.

We hope that this problem has been resolved.

+3
source

I got this error at Unity 2018 and I think it is a mistake.

Fix for me: add package name in Android Manifest in Unity project.

In my project, the path to the manifest: Assets/Plugins/Android/AndroidManifest.xml

For example, I got an error when my manifest file looks like this:

 <?xml version="1.0" encoding="utf-8" standalone="no"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android"> ... </manifest> 

It is generated by the Unity Oculus Gear VR plugin. But it missed the package name and should look like this:

 <?xml version="1.0" encoding="utf-8" standalone="no"?> <manifest package="YOURPACKAGENAME" xmlns:android="http://schemas.android.com/apk/res/android"> ... </manifest> 

Replace YOURPACKAGENAME with the Package Name of your project. It should be in the menu "Edit" β†’ "Project Settings" β†’ "Player" β†’ "Other Settings" β†’ "Identification" β†’ "Package Name" and should look like com.YOURORGANIZATION.APPNAME.

Some nations wrote that the manifest should look like this:

 <?xml version="1.0" encoding="utf-8" standalone="no"?> <manifest package="${applicationId}" xmlns:android="http://schemas.android.com/apk/res/android"> ... </manifest> 

And they wrote that Unity will replace ${applicationId} in the package name when building the Android application, but in my Unity 2018.1.6f1 this does not work, and I think this is also a mistake.

+3
source

Your second <action android:name="android.intent.action.MAIN" /> and <category android:name="android.intent.category.LAUNCHER" /> are not allowed here. I think `<manifest xmlns: android =" http://schemas.android.com/apk/res/android "package =" com.example.brandon.MineDodge ">

 <application android:allowBackup="true" android:icon="@mipmap/redjet" android:label="@string/app_name" android:theme="@style/AppTheme" > <activity android:name="com.example.brandon.MineDodge.MainActivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> </activity> <activity android:name="com.example.brandon.MineDodge.Splash" /> </application> 

`It will be fine.

0
source

why did you mention <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> twice? Remove either of these two.

0
source

I had this in a project with several subprojects called by a subproject that does not match the configure( clause configure( at the top level of build.gradle .

In particular, I had

 configure(subprojects.findAll { it.name.startsWith("pachymeninx") }) { 

which does not match my new subproject called pachymen . But the Gradle build process did not give a warning (what I saw) and instead gave the error " Cannot read packageName from AndroidManifest.xml " for the pachymen subproject.

0
source

This is simply because you either copied an existing project or its files into your newly created project. So the manifest conflict. Because the copy of the manifest belongs to another project and its paths.

you need to recreate the manifest file in your own path to the project file and possibly manually copy the different project manifest code into your newly created manifest file.

0
source

In response to Eldar Kurbanov, who had this error in Unity and all who find this question after an error while building with gradle in Unity.

This is not a Unity 2018 β€œbug” and not the reason that something is missing in the Manifest pre-build. This is actually because there is no line in the mainTemplate.gradle file:

 applicationId '**APPLICATION**' 

Inside the defaultConfig {} block of the android {} section. This will ensure that the package name is inserted into the generated manifest.

Yes, manually inserting the package name into the main manifest will work, but it's much better to just use the Unity project settings to set the package name, rather than hard code it.

If someone else finds this question and uses Unity, here is an example of mainTemplate.gradle that you can use for links: https://pastebin.com/hPs0uvkZ

0
source

My problem was that I was trying to convert an old Eclipse project to an Android Studio project, where the manifest file should be in a different place (along with other files). Specifically, the project \ app \ src \ main

0
source

In my case, the src folder was missing, so I created one folder inside the application and inside it, in which another main folder was created, copying and pasting the manifest file there, and finally synchronizing with the Gradle files, and it compiled successfully.

0
source

try it,

 <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.brandon.MineDodge"> <application android:icon="@drawable/launchicon" android:label="@string/app_name" android:theme="@style/AppTheme"> <activity android:name=".MainActivity" android:screenOrientation="portrait" android:theme="@style/AppBaseThemeTP"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".Splash" android:screenOrientation="portrait" android:theme="@style/AppBaseThemeTP" > </activity> </application> </manifest> 
-1
source
 <activity android:name="com.example.brandon.MineDodge.Splash" /> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </application> 

change it to -

  <activity android:name="com.example.brandon.MineDodge.Splash" /> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </application> 
-2
source

All Articles