Cannot read packageName from AndroidManifest.xml

匿名 (未验证) 提交于 2019-12-03 01:12:01

问题:

I have errors in my android manifest file:

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> 

回答1:

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



回答2:

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.



回答3:

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.



回答4:

why you mentioned <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> twice? Remove any one from those two.



回答5:

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> 

` That will be OK.



回答6:

I had this in a multi-subproject project, caused by the subproject not matching the configure( clause in the top-level build.gradle.

Specifically I had

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

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



回答7:

Thats simply because you either copied an already existing project and its files into your newly created project. Thereby causing Manifest conflict. Because the manifest copied belongs to the other project and its paths.

you need to recreated a manifest file in your own project file path and possibly manually copy the other project's manifest code into your newly created manifest file.



回答8:

In response to Eldar Kurbanov who had this error in Unity & anyone else who finds this question after having the error when building with gradle in Unity.

This is not a Unity 2018 'bug' nor is it caused by something being missing from the Manifest pre-build. It's actually caused by the mainTemplate.gradle file missing the line:

applicationId '**APPLICATION**' 

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

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

If anyone else finds this question and they're using Unity then here's an example mainTemplate.gradle you can use for referencing: https://pastebin.com/hPs0uvkZ



回答9:

try this ,

<?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> 


回答10:

<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> 


易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!