简体   繁体   English

无法从 AndroidManifest.xml 读取 packageName

[英]Cannot read packageName from AndroidManifest.xml

I have errors in my android manifest file:我的 android 清单文件中有错误:

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>

If you are using an old version of build.grade file, you should remove this code:如果您使用的是旧版本的build.grade文件,您应该删除以下代码:

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注意:如果您看到此代码,则您使用的是旧版本

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.此外,用于 MainActivity 的意图过滤器也必须类似地用于第二个活动。

Hope this issue is resolved.希望这个问题得到解决。

I got this error on Unity 2018 and i think it's a bug.我在 Unity 2018 上遇到了这个错误,我认为这是一个错误。

Fix for me: Add packagename to Android Manifest in Unity project.为我修复:在 Unity 项目中将 packagename 添加到 Android Manifest。

In my project path to manifest: Assets/Plugins/Android/AndroidManifest.xml在我的项目清单路径中: 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.它由 Unity 的 Oculus Gear VR 插件生成。 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.将 YOURPACKAGENAME 替换为项目的包名称。 It should be in Edit -> Project Settings -> Player -> Other Settings -> Identification -> Package Name and should looks like com.YOURORGANIZATION.APPNAME它应该在 Edit -> Project Settings -> Player -> Other Settings -> Identification -> Package Name 中,看起来像 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.他们写道,在构建 android 应用程序时,Unity 将替换包名称上的${applicationId} ,但在我的 Unity 2018.1.6f1 中它不起作用,我认为这也是一个错误。

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).我的问题是我试图将一个旧的 Eclipse 项目转换为 Android Studio 项目,其中清单文件预计位于不同的位置(以及其他文件)。 Specifically project\\app\\src\\main特别是project\\app\\src\\main

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.回应在 Unity 中出现此错误的Eldar Kurbanov以及在 Unity 中使用 gradle 构建时出现错误后发现此问题的任何其他人。

This is not a Unity 2018 'bug' nor is it caused by something being missing from the Manifest pre-build.这不是 Unity 2018 的“错误”,也不是由清单预构建中缺少某些内容引起的。 It's actually caused by the mainTemplate.gradle file missing the line:它实际上是由 mainTemplate.gradle 文件缺少该行引起的:

applicationId '**APPLICATION**'

Inside the defaultConfig {} block of the android {} section.android {}部分的defaultConfig {}块内。 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.是的,手动将包名插入到主清单中是可行的,但最好使用 Unity 的项目设置来设置包名,而不是对其进行硬编码。

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如果其他人发现这个问题并且他们正在使用 Unity,那么这里有一个 mainTemplate.gradle 示例,您可以用于参考: https : //pastebin.com/hPs0uvkZ

Your second <action android:name="android.intent.action.MAIN" /> and <category android:name="android.intent.category.LAUNCHER" /> are not allowed here.您的第二个<action android:name="android.intent.action.MAIN" /><category android:name="android.intent.category.LAUNCHER" />在这里是不允许的。 I think ` < manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.brandon.MineDodge" >我认为` <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. ` 没问题。

why you mentioned <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> twice?为什么你提到<action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" />两次? Remove any one from those two.从这两个中删除任何一个。

I had this in a multi-subproject project, caused by the subproject not matching the configure( clause in the top-level build.gradle .我在一个多子项目项目中遇到了这个,这是由于子项目与顶级build.gradleconfigure(子句不匹配造成的。

Specifically I had具体我有

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

which did not match my new subproject called pachymen .这与我名为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.但是 Gradle 构建过程没有发出警告(我看到了),而是为pachymen子项目给出了“ Cannot read packageName from AndroidManifest.xml ”错误。

Thats simply because you either copied an already existing project and its files into your newly created project.那只是因为您将现有项目及其文件复制到新创建的项目中。 Thereby causing Manifest conflict.从而导致Manifest 冲突。 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.您需要在您自己的项目文件路径中重新创建一个清单文件,并可能手动将其他项目的清单代码复制到您新创建的清单文件中。

检查您的 src 文件是否以不同的名称命名.....如果是这种情况,那么您最终可能会遇到此错误....将其重命名为“src

check your manifest file should be at-> \\android\\app\\src\\main\\AndroidManifest.xml检查您的清单文件应该在-> \\android\\app\\src\\main\\AndroidManifest.xml

otherwise android can't find the package name in Manifest file from a specific location否则android无法从特定位置在Manifest文件中找到包名

In my case, the module level android manifest file was in the wrong location.就我而言,模块级别的 android 清单文件位于错误的位置。 It was inside src/java/ whereas it is supposed to be in src/它在src/java/而它应该在src/

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>

android:name="com.example.brandon.MineDodge.MainActivity"应该在<application> ,而不是<activity>

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM