Java 无法从 AndroidManifest.xml 读取 packageName
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/32447683/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Cannot read packageName from AndroidManifest.xml
提问by user4192325
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>
回答by Andy.Zhao
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" >
你的第二个<action android:name="android.intent.action.MAIN" />
,
<category android:name="android.intent.category.LAUNCHER" />
不允许在这里。我认为` <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.
` 没问题。
回答by Raju-san
why you mentioned <action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
twice? Remove any one from those two.
为什么你提到了 <action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
两次?从这两个中删除任何一个。
回答by Amit Vaghela
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>
回答by RajSharma
<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>
回答by Prithviraj Prabhu
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.
希望这个问题得到解决。
回答by SandroMarques
If you are using an old version of build.gradefile, 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
注意:如果您看到此代码,则您使用的是旧版本
回答by WillC
I had this in a multi-subproject project, caused by the subproject not matching the configure(
clause in the top-level build.gradle
.
我在一个多子项目项目中遇到了这个问题,这是由于子项目configure(
与顶级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.
这与我名为pachymen
. 但是 Gradle 构建过程没有发出警告(我看到的),而是Cannot read packageName from AndroidManifest.xml
为pachymen
子项目给出了“ ”错误。
回答by sinopi
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.
那只是因为您将现有项目及其文件复制到新创建的项目中。从而导致Manifest 冲突。因为复制的清单属于另一个项目及其路径。
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.
您需要在您自己的项目文件路径中重新创建一个清单文件,并可能手动将其他项目的清单代码复制到您新创建的清单文件中。
回答by Eldar Kurbanov
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. But it missed package name and must looks like this:
它由 Unity 的 Oculus Gear VR 插件生成。但它错过了包名,必须是这样的:
<?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
将 YOURPACKAGENAME 替换为项目的包名称。它应该在 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.
他们写道,${applicationId}
在构建 android 应用程序时,Unity 将替换包名称,但在我的 Unity 2018.1.6f1 中它不起作用,我认为这也是一个错误。
回答by Sean McManus
In response to Eldar Kurbanovwho 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. It's actually caused by the mainTemplate.gradle file missing the line:
这不是 Unity 2018 的“错误”,也不是由清单预构建中缺少某些内容引起的。它实际上是由 mainTemplate.gradle 文件缺少该行引起的:
applicationId '**APPLICATION**'
Inside the defaultConfig {}block of the android {}section. This will ensure the generated manifest has the package name inserted into it.
在android {}部分的defaultConfig {}块内。这将确保生成的清单中插入了包名称。
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