安装错误:INSTALL_PARSE_FAILED_MANIFEST_MALFORMED?
我正在开发一个小应用程序,其中列出了 Android 设备上存在/安装的所有应用程序。但是当我尝试运行代码时出现以下错误。
安装错误:INSTALL_PARSE_FAILED_MANIFEST_MALFORMED
请任何人帮助我解决此错误。
I am developing a small application that lists all the applications present/ installed on the android device. But I'm getting the below error while i'm trying to run the code.
Installation error: INSTALL_PARSE_FAILED_MANIFEST_MALFORMED
Please can any one help me to sort out this error.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(30)
此错误可能还有其他原因。该属性
应始终以点开头,例如:
There could be another reason for this error. The attribute
Should always start with a dot, like:
活动名称应以“.”为前缀。在你的清单文件中。
Activity name should be prefixed with "." in your manifest file.
在Android 12或Android S中[您可以检查将targetSdkVersion“S”设置为targetSdkVersion 30,它将正常工作]。为此,为了工作,我们需要将所有依赖项更新到最新的依赖项,并且必须将 - 添加
到在应用程序的 AndroidManifest.xml 文件中声明了意图过滤器的任何活动、活动别名、服务或接收器组件。因为 Android 12 中的行为发生了一些变化。
In Android 12 or Android S [You can check to make targetSdkVersion "S" to targetSdkVersion 30 it will work fine]. For this, to work we need to update all of our dependencies to the latest one and have to add -
to to any activity, activity-alias, service, or receiver components that have intent-filters declared in the app’s AndroidManifest.xml file. Because there are few behaviors changed in Android 12.
INSTALL_PARSE_FAILED_MANIFEST_MALFORMED 错误代码由 PackageParser.java 返回
当它检测到manifest.xml 文件中存在大量错误时。
要隔离错误,请查看 logcat(当您执行“adb install foo.apk”命令时)。在我遇到的问题中,logcat包含:
在上面的第四行中,您可以看到PackageParser抱怨manifest.xml文件的第214行“不包含权限属性” 。请参阅下面的 PackageParser 中返回该错误代码的所有情况的列表。 (PackageParser 是唯一产生 PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED 错误代码的类)
在我的例子中,消息“不包括权限属性”是由 parseApplication 调用的 parseProvider 函数中 PackagerParser.java 的第 2490 行生成的。
从frameworks/base/core/java/android/content/pm/PackageParser.java 4.1.1版本开始,这些方法中的这些行引用了PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED。如果源代码行号后跟一个带引号的字符串,则该字符串是 logcat 中打印的消息。如果行号后跟一个 Java 表达式,该表达式是导致返回错误代码的代码,则应该调查该函数以查看导致返回错误消息的原因。在某些情况下,我无法将错误原因隔离到一个特定的方法调用。
遗憾的是,您必须在 logcat 和源代码中查找才能找出导致问题的原因。
The INSTALL_PARSE_FAILED_MANIFEST_MALFORMED error code is returned by PackageParser.java
when it detects any of a large number of errors in the manifest.xml file.
To isolate the error, look in logcat (when you do the 'adb install foo.apk' command). In the problem I encountered, logcat contained:
In the fourth line above, you can see that PackageParser complains that line #214 of the manifest.xml file "<provider> does not include authorities attribute". See the listing below of all the cases in PackageParser that returns that error code. (PackageParser is the only class that produces the PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED error code)
In my case the message "<provider> does not include authorities attribute" is produced by line 2490 of PackagerParser.java in the parseProvider function called by parseApplication.
From the 4.1.1 version of frameworks/base/core/java/android/content/pm/PackageParser.java, PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED is referenced on these lines in these methods. If the source code line number is followed by a quoted string that is the message printed in logcat. if the line number is followed by a Java expression that is the code that caused that error code to be returned that that function should be investigated to see what caused the error message to be returned. In a couple cases I couldn't isolate the error cause to one specific method call.
It's regrettable that you have to poke around in logcat and the source to figure out what causes a problem.
我遇到此错误是因为
在我将其更改为类似
解决方案后,我的包名称中有大写字母
I was having this error because i had capital letters in my package name like this
after i had changed it to something like
it was solved
像这样添加
到 Manifest.xml 中的活动中
;
Add
to your activity in Manifest.xml
Like this;
检查清单文件中的活动名称
或主活动/类中的包名称
Check your Activity name in manifest file
or the Package name in main activity/class
我有同样的问题,但是当我这样调用流程时:
当我更改为:
一切都开始工作。
I have the same issue but when i call process like this:
When i change to:
Everything starts working.
我不久前遇到了同样的问题,在 android docs 他们说如果你在
android:process
中不使用“:”作为前缀,你应该使用小写字母,但他们从来没有这么说过,那么它应该是一个像包一样的进程名称,就像com.company.app.services.MyService
I ran into the same problem time ago, in the android docs they said that if you don't use ":" as prefix in
android:process
you should use a lower case letter, but they never said that, then it should be a package like process name, likecom.company.app.services.MyService
任何名称,例如
android:name
、android:process
都应采用包名称的形式:以a..z
开头,与其他名称组合以.
结尾,不要以.
结尾...Any name such as
android:name
,android:process
should be in form of package name: starts witha..z
, combines with others with.
, do not end with.
...写了(注意 - 与 _):。
我的问题是我在一项活动下 这也可能是导致您出现问题的原因。
My issue was that I had written (Notice the - vs. the _):
under an activity. This might be the cause of your issue as well.
阅读您的 Android 设备日志来诊断此错误。期待“W/PackageParser”行解释该问题。
Read your Android device logs to diagnose this error. Expect a "W/PackageParser" line explaining the problem.
就我而言,我指的是使用如下属性的图标:
而不是可绘制的:
我在多个地方使用此属性,但它似乎在清单中不起作用。
In my case I was referring to an icon using an attribute like this:
instead of the drawable:
I am using this attribute in several places but it seems it does not work in manifest.
由于以下代码,我遇到了此错误:
当我将
android:mimeType="*"
更改为android:mimeType="*/*"
时,它修复了该错误。I had this error because of the code below:
When I changed
android:mimeType="*"
toandroid:mimeType="*/*"
, it fixed the error.遇到同样的错误!
有空的权限标签,这就是导致问题的原因!
Got the same error!
had empty permission tag and that was causing the problem!
添加本地化后,我遇到了同样的问题
字符串
@string/version_name
意外传递到新添加的本地化字符串文件之一(它仅出现在新文件中)。检查所有本地化并从除 eng 语言环境之外的每个文件中删除
@string/version_name
后,一切再次正常工作I run into the same problem after adding localizations
The string
@string/version_name
accidentally passed into one of new added localized string-file (it appeared only in the new files).After checking all the localizations and removing
@string/version_name
from every file except eng locale everything worked again必须在之前定义
must be defined BEFORE
活动创建的名称文件夹必须是小写字母,不要使用大写字母作为活动文件夹名称......使用小写字母总是更好。
activity created name folder must be small letters, Dont use capital letters for activity folder name.... its always better to use small letters.
这可能有很多原因,但对我来说,这是通过将包的名称更改为小写名称来解决的(包名称是“活动”,用“活动”解决)。
this can be for many reasons , but for me it was solved by changing the name of package with lowercase name (package name was Activities , solved with activities) .
[解决方案]
转到您的项目文件夹并打开 AndroidManifest.xml 文件
中添加以下代码
在活动android:exported="true"
示例
[Solution]
Go to your project folder and open AndroidManifest.xml file
Add the below code in activity
android:exported="true"
Example
如果您在清单中使用 multidex,则应为其添加值或资源。
就像..
或者
然后清理项目并重新安装应用程序。
If you are using multidex in manifest then it should be added with value or resource.
Like..
OR
then clean the project and reinstall the app.
我创建了一个新应用程序并将其定位到 Android Pie。一切都运行良好,但最近我发现我的应用程序无法安装到 Android 操作系统的 Android Naught 及以下版本。
安装时,我看到失败消息
因此,我所做的修复如下,它们都只需要在
AndroidManifest.xml
文件中完成。对于活动、服务、接收器和所有
清单权限,
这些都是我必须执行的更改,以使其也适用于较低版本的设备。
I create a new application and target it to Android Pie. Everything was working well and good then lately I found that my application don't installs to Android Naught and below version of Android OS.
While installing, I see failure message
So what fixes which I made are as follow and they all need to be done in
AndroidManifest.xml
file only.For activity, service, receiver and all
For Manifest permissions
That were all changes which I had to perform to make it work for lower version devices as well.
需要在
之前指定目标
。Target
<activity>
needs to be specified before the<activity-alias>
.如果您在 Android 12 或 Android S 中使用目标 api 31 或 32,那么您会遇到此错误,请解决此问题
将此行添加到 laucher Activity in Manifest
该元素设置 Activity 是否可以由其他应用程序的组件启动:
通过其确切的类名称。
相同的应用程序、具有相同用户 ID 或特权的应用程序
系统组件。当没有意图时这是默认值
过滤器。
是否应为此 Activity 启用硬件加速渲染 — 如果应启用则为“true”,否则为“false”。默认值为“假”。
if you're using target api 31 or 32 in Android 12 or Android S so you'd face this error to solve this
Add this line to the laucher activity in Manifest
This element sets whether the activity can be launched by components of other applications:
by its exact class name.
same application, applications with the same user ID, or privileged
system components. This is the default value when there are no intent
filters.
Whether or not hardware-accelerated rendering should be enabled for this Activity — "true" if it should be enabled, and "false" if not. The default value is "false".
我在 Android 12 上遇到了同样的问题,并修复了这个问题:
如果您的应用程序以 Android 12 或更高版本为目标,并且包含使用意图过滤器的活动、服务或广播接收器,则必须为这些应用程序组件显式声明 android:exported 属性。
如果应用程序组件包含 LAUNCHER 类别,请将 android:exported 设置为 true。在大多数其他情况下,将 android:exported 设置为 false。
我还更新了第三方依赖项。
I had same issue on Android 12 and fixed it this:
If your app targets Android 12 or higher and contains activities, services, or broadcast receivers that use intent filters, you must explicitly declare the android:exported attribute for these app components.
If the app component includes the LAUNCHER category, set android:exported to true. In most other cases, set android:exported to false.
Also I updated third party Dependencies.
如果您有 AndroidStudio 4.1.2 尝试添加:
android:exported="true"
&文件“AndroidManifest.xml”中的android.name=".MainActivity"
您的应用程序 &活动应该是这样的:
If you have AndroidStudio 4.1.2 try to add :
android:exported="true"
&android.name=".MainActivity"
in the file "AndroidManifest.xml"Your application & activity should seen be this way:
问题
此
INSTALL_PARSE_FAILED_MANIFEST_MALFORMED
错误仅表明您的清单(或项目和依赖项中的清单之一)中存在错误,当应用程序被推送到模拟器或设备进行安装。这些运行时错误不会阻止 Android Studio 中项目的编译,因此乍一看您会看到“构建成功”,一切看起来都很好。
找到实际的根源
最好的解决方案是首先确保您拥有最新的构建工具。这将增加获得如下所示的正确错误详细信息的可能性。您可以通过打开 Android Studio 底部的“运行”选项卡来查看安装 adb 命令的结果。
使用所有默认设置,该窗口应在运行应用程序后打开。如果没有,则可以在此处找到它(也在默认布局上)。
我也将完整的错误消息粘贴到此处,以便您可以清楚地看到,在我的情况下,详细消息清楚地表明清单中的问题是什么。这里;
AddLinkActivity
活动声明中缺少export
标记。替代方法
如果由于某种原因,该详细消息丢失或不够清晰,无法指出根本原因,则替代方法是打开项目中的
AndroidManifest.xml
文件,然后打开问题
选项卡。此视图是当选择
当前文件
时在该特定文件上发现的所有错误和警告的列表。在文件本身中,您还可以看到编辑器中标记了
Activity
声明。包括一个快速修复工具提示以添加缺少的export
标签。The Problem
This
INSTALL_PARSE_FAILED_MANIFEST_MALFORMED
error only indicates there is an error within your manifest (or one of the manifests in your project & dependencies) that manifested (pun intended) itself when the app was pushed to an emulator or device for installation.These runtime errors won't block compilation of the the project within Android Studio so at first view you get a
Build Success
and everything seems fine.Finding the actual root source
Best solution is to start by making sure you have the latest build tools. That will increase the likelihood of having a proper error detail message like the one listed below. You can find this by opening the
Run
tab at the bottom in Android Studio to see the outcome of the installation adb commands.With all default settings this window should open after running the app. If not this is where to find it (also on a default layout that is).
I've pasted the full error message here also so you can clearly see that in my case the detail message clearly indicates what the issue in the manifest is. Here; a missing
export
tag on theAddLinkActivity
activity declaration.Alternative Approach
If, for whatever reason, that detail message is missing or not clear enough to point to the root cause an alternative approach is to open the
AndroidManifest.xml
file in your project and then open theProblems
tab.This view is a list of all the errors and warnings found on that specific file, when
Current File
is selected.In the file itself you can also see that the
Activity
declaration is marked in the editor. Including a quick fix tooltip to add the missingexport
tag.可能还有其他格式错误但未在 IDE 中突出显示的文件,例如清单可能会引用标签等内容的 res/values/strings。
There could be other files that are malformed but aren't highlighted in the IDE, for example the res/values/strings which the manifest may reference for things like labels.
就我而言,原因是 << 中缺少 android:name 属性。活动别名>。
这是强制性的<活动别名>尽管它不能命名现有的类。
有趣的是 - 该项目编译没有问题。
In my case the cause was absence of android:name attribute in < activity-alias >.
It is obligatory for < activity-alias > although it must not name an existing class.
Funny thing is - the project compiles without problems.