Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot read packageName from AndroidManifest.xml

I have errors in my 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 to look on this website but the answers aren't working 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>
like image 465
user4192325 Avatar asked Sep 08 '15 00:09

user4192325


4 Answers

If you are using an old version of build.grade file, you should 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

like image 196
SandroMarques Avatar answered Nov 17 '22 09:11

SandroMarques


The error is really simple, and I'm rather dissapointed with the stack community to not have found it till now.

< manifest ...

should become

<manifest...

Basically, remove that extra space. That's what's causing the following error :

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

Also, the intent-filter used for the MainActivity, must similarly be used for the second activity.

Hope this issue is resolved.

like image 22
Prithviraj Prabhu Avatar answered Nov 17 '22 10:11

Prithviraj Prabhu


I got this error on Unity 2018 and i think it's a bug.

Fix for me: Add packagename to Android Manifest in Unity project.

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

For example i got 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 generated by Oculus Gear VR plugin by Unity. But it missed package name and must looks 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 to Package Name of your project. It should be in Edit -> Project Settings -> Player -> Other Settings -> Identification -> Package Name and should looks like com.YOURORGANIZATION.APPNAME

Some peoples wrote, that manifest must looks 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} on package name when build android application, but in my Unity 2018.1.6f1 it doesn't work and i think it's a bug too.

like image 4
Eldar Kurbanov Avatar answered Nov 17 '22 09:11

Eldar Kurbanov


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

like image 2
Jan Málek Avatar answered Nov 17 '22 09:11

Jan Málek