Android Studio 3.0清单错误:找到未知元素

时间:2021-08-12 20:56:53

NOTICE: Please do not post this "android.enableAapt2=false" as an answer. It is not a solution. It is just ignoring the real error which is not causing any problem on runtime.

注意:请不要将此“android.enableAapt2 = false”作为答案发布。这不是一个解决方案。它只是忽略了在运行时没有引起任何问题的真正错误。

Solution was simple, just removed mistakenly placed action tag outside of an intent filter in the manifest file.

解决方案很简单,只是在清单文件中的intent过滤器之外删除了错误放置的操作标记。

Have an application which was building by Android Studio 2.3 fine. After updating Android Studio 3.0 Stable, started to having this error and unable to build my project.

有一个由Android Studio 2.3构建的应用程序很好。更新Android Studio 3.0 Stable后,开始出现此错误并无法构建我的项目。

Here my manifest.xml

这是我的manifest.xml

<application
    android:name=".ApplicationClass"
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:largeHeap="true"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">

    <!--other unrelated stuff-->

    <action android:name="com.google.android.c2dm.intent.REGISTRATION" />

    <receiver
        android:name="com.google.android.gms.gcm.GcmReceiver"
        android:exported="true"
        android:permission="com.google.android.c2dm.permission.SEND">
        <intent-filter>
            <action android:name="com.google.android.c2dm.intent.RECEIVE" />
            <category android:name="com.xxx.xxx" />
        </intent-filter>
    </receiver>
</application>

Error shows this line:

错误显示此行:

<action android:name="com.google.android.c2dm.intent.REGISTRATION" />

If I comment/remove this action tag line, the project builds fine but it is necessary for GCM and I cannot remove it.

如果我评论/删除此操作标记行,项目构建正常但GCM是必要的,我无法删除它。

As you see the logs, The error not occurs at main manifest file, occurs at /build/intermediates/manifests/full/debug/AndroidManifest.xml

当您看到日志时,主清单文件中不会发生错误,发生在/build/intermediates/manifests/full/debug/AndroidManifest.xml

Tried cleaning, rebuilding, disabling instant run. Is there any solution?

尝试清洁,重建,禁用即时运行。有什么解决方案吗?

The Error Logs:

错误日志:

/THE_PROJECT_PATH/app/build/intermediates/manifests/full/debug/AndroidManifest.xml
Error:(99) error: unknown element <action> found.
Error:(99) unknown element <action> found.
Error:java.util.concurrent.ExecutionException: java.util.concurrent.ExecutionException: com.android.tools.aapt2.Aapt2Exception: AAPT2 error: check logs for details
Error:java.util.concurrent.ExecutionException: com.android.tools.aapt2.Aapt2Exception: AAPT2 error: check logs for details
Error:com.android.tools.aapt2.Aapt2Exception: AAPT2 error: check logs for details
Error:Execution failed for task ':app:processDebugResources'.
> Failed to execute aapt
Information:BUILD FAILED in 1s
Information:6 errors
Information:0 warnings
Information:See complete output in console

8 个解决方案

#1


28  

You have a misplaced tag. The new AAPT (AAPT2) now throws an error on this.

你有一个错位的标签。新的AAPT(AAPT2)现在抛出了一个错误。

From the docs in here: https://developer.android.com/studio/build/gradle-plugin-3-0-0-migration.html

来自这里的文档:https://developer.android.com/studio/build/gradle-plugin-3-0-0-migration.html

Behavior changes when using AAPT2


To improve incremental resource processing, Android plugin 3.0.0 enables AAPT2 by default. Although AAPT2 should immediately work with older projects, this section describes some behavior changes that you should be aware of.

为了改进增量资源处理,Android插件3.0.0默认启用AAPT2。虽然AAPT2应该可以立即使用较旧的项目,但本节介绍了一些您应该注意的行为更改。

Element hierarchies in the Android manifest

In previous versions of AAPT, elements nested in incorrect nodes in the Android manifest are either ignored or result in a warning. For example, consider the following sample:

在以前版本的AAPT中,嵌套在Android清单中不正确节点中的元素将被忽略或导致警告。例如,请考虑以下示例:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
   package="com.example.myname.myapplication">
   <application
       ...
       <activity android:name=".MainActivity">
           <intent-filter>
               <action android:name="android.intent.action.MAIN" />
               <category android:name="android.intent.category.LAUNCHER" />
           </intent-filter>
           <action android:name="android.intent.action.CUSTOM" />
       </activity>
   </application>
</manifest>

Previous versions of AAPT would simply ignore the misplaced tag. However, with AAPT2, you get the following error:

以前版本的AAPT只会忽略错位标签。但是,使用AAPT2,您会收到以下错误:

AndroidManifest.xml:15: error: unknown element <action> found.

To resolve the issue, make sure your manifest elements are nested correctly. For more information, read Manifest file structure.

要解决此问题,请确保您的清单元素已正确嵌套。有关更多信息,请阅读Manifest文件结构。

#2


13  

add this code in gradle.properties in the root project:

在根项目的gradle.properties中添加此代码:

android.enableAapt2=false

this worked for me

这对我有用

root 
| 
|--gradle.properties

#3


1  

In order to summarize and simplify: you should just concentrate on your main AndroidManifest.xml file and check whether it strictly follows the sequence as well as nesting of XML tags as described in https://developer.android.com/guide/topics/manifest/manifest-intro.html. Otherwise the IDE will open up the debug-level AndroidManifest.xml showing a lot of error every time you try to clean/build the project and make you confused!

为了总结和简化:您应该专注于您的主AndroidManifest.xml文件,并检查它是否严格遵循序列以及XML标记的嵌套,如https://developer.android.com/guide/topics/中所述清单/清单-intro.html。否则,IDE将打开调试级别的AndroidManifest.xml,每次您尝试清理/构建项目时都会显示很多错误并让您感到困惑!

#4


0  

Just rename your manifest file like this: AndroidManifest.xmlold, then create a new XML file and give name: AndoridManifest.xml. Then just copy the content of the old file after you remove line with tag . Build>Clean Project and then Run>debug app again. Then the problem will be disappeared.

只需将您的清单文件重命名为:AndroidManifest.xmlold,然后创建一个新的XML文件并输入名称:AndoridManifest.xml。然后在删除带有标记的行后,只复制旧文件的内容。构建>清理项目,然后再次运行>调试应用程序。然后问题就会消失。

#5


0  

We have the solution of this problem and solution is that service always comes under child form of <Application <service>> when we write the code outside of <Application> then issue occur. Services are the child part of Application in Manifest... okay... It will sure work..do it

我们有这个问题的解决方案,解决方案是当我们在 之外编写代码然后发生问题时,服务总是在 >的子形式下。服务是应用程序在清单中的子代...好吧......它肯定会工作......它

#6


0  

Put action content in intent-filter like below as per Manifest file structure.

根据Manifest文件结构将操作内容放在intent-filter中,如下所示。

<intent-filter>
        <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
 </intent-filter>

#7


0  

I recently had this fix on my gradle.properties but a warning saying that "The option 'android.enableAapt2' is deprecated..." kept on coming and the solution was to change it to true instead.

我最近对我的gradle.properties进行了此修复,但警告说“选项'android.enableAapt2'已被弃用......”一直在进行,解决方案是将其更改为true。

#8


-1  

In my app in AndroidManifest.xml tag receiver was under the application tag and this was cause of build fail with message .../android/app/build/intermediates/manifests/full/debug/AndroidManifest.xml:25: AAPT: error: unknown element <receiver> found. After i have put it in application tag then the project has been compiled successfully. That's all

在AndroidManifest.xml中的应用程序标签接收器位于应用程序标签下,这是构建失败的原因,消息为... / android / app / build / intermediates / manifests / full / debug / AndroidManifest.xml:25:AAPT:error :找到未知元素 。在我将其放入应用程序标记后,该项目已成功编译。就这样

#1


28  

You have a misplaced tag. The new AAPT (AAPT2) now throws an error on this.

你有一个错位的标签。新的AAPT(AAPT2)现在抛出了一个错误。

From the docs in here: https://developer.android.com/studio/build/gradle-plugin-3-0-0-migration.html

来自这里的文档:https://developer.android.com/studio/build/gradle-plugin-3-0-0-migration.html

Behavior changes when using AAPT2


To improve incremental resource processing, Android plugin 3.0.0 enables AAPT2 by default. Although AAPT2 should immediately work with older projects, this section describes some behavior changes that you should be aware of.

为了改进增量资源处理,Android插件3.0.0默认启用AAPT2。虽然AAPT2应该可以立即使用较旧的项目,但本节介绍了一些您应该注意的行为更改。

Element hierarchies in the Android manifest

In previous versions of AAPT, elements nested in incorrect nodes in the Android manifest are either ignored or result in a warning. For example, consider the following sample:

在以前版本的AAPT中,嵌套在Android清单中不正确节点中的元素将被忽略或导致警告。例如,请考虑以下示例:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
   package="com.example.myname.myapplication">
   <application
       ...
       <activity android:name=".MainActivity">
           <intent-filter>
               <action android:name="android.intent.action.MAIN" />
               <category android:name="android.intent.category.LAUNCHER" />
           </intent-filter>
           <action android:name="android.intent.action.CUSTOM" />
       </activity>
   </application>
</manifest>

Previous versions of AAPT would simply ignore the misplaced tag. However, with AAPT2, you get the following error:

以前版本的AAPT只会忽略错位标签。但是,使用AAPT2,您会收到以下错误:

AndroidManifest.xml:15: error: unknown element <action> found.

To resolve the issue, make sure your manifest elements are nested correctly. For more information, read Manifest file structure.

要解决此问题,请确保您的清单元素已正确嵌套。有关更多信息,请阅读Manifest文件结构。

#2


13  

add this code in gradle.properties in the root project:

在根项目的gradle.properties中添加此代码:

android.enableAapt2=false

this worked for me

这对我有用

root 
| 
|--gradle.properties

#3


1  

In order to summarize and simplify: you should just concentrate on your main AndroidManifest.xml file and check whether it strictly follows the sequence as well as nesting of XML tags as described in https://developer.android.com/guide/topics/manifest/manifest-intro.html. Otherwise the IDE will open up the debug-level AndroidManifest.xml showing a lot of error every time you try to clean/build the project and make you confused!

为了总结和简化:您应该专注于您的主AndroidManifest.xml文件,并检查它是否严格遵循序列以及XML标记的嵌套,如https://developer.android.com/guide/topics/中所述清单/清单-intro.html。否则,IDE将打开调试级别的AndroidManifest.xml,每次您尝试清理/构建项目时都会显示很多错误并让您感到困惑!

#4


0  

Just rename your manifest file like this: AndroidManifest.xmlold, then create a new XML file and give name: AndoridManifest.xml. Then just copy the content of the old file after you remove line with tag . Build>Clean Project and then Run>debug app again. Then the problem will be disappeared.

只需将您的清单文件重命名为:AndroidManifest.xmlold,然后创建一个新的XML文件并输入名称:AndoridManifest.xml。然后在删除带有标记的行后,只复制旧文件的内容。构建>清理项目,然后再次运行>调试应用程序。然后问题就会消失。

#5


0  

We have the solution of this problem and solution is that service always comes under child form of <Application <service>> when we write the code outside of <Application> then issue occur. Services are the child part of Application in Manifest... okay... It will sure work..do it

我们有这个问题的解决方案,解决方案是当我们在 之外编写代码然后发生问题时,服务总是在 >的子形式下。服务是应用程序在清单中的子代...好吧......它肯定会工作......它

#6


0  

Put action content in intent-filter like below as per Manifest file structure.

根据Manifest文件结构将操作内容放在intent-filter中,如下所示。

<intent-filter>
        <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
 </intent-filter>

#7


0  

I recently had this fix on my gradle.properties but a warning saying that "The option 'android.enableAapt2' is deprecated..." kept on coming and the solution was to change it to true instead.

我最近对我的gradle.properties进行了此修复,但警告说“选项'android.enableAapt2'已被弃用......”一直在进行,解决方案是将其更改为true。

#8


-1  

In my app in AndroidManifest.xml tag receiver was under the application tag and this was cause of build fail with message .../android/app/build/intermediates/manifests/full/debug/AndroidManifest.xml:25: AAPT: error: unknown element <receiver> found. After i have put it in application tag then the project has been compiled successfully. That's all

在AndroidManifest.xml中的应用程序标签接收器位于应用程序标签下,这是构建失败的原因,消息为... / android / app / build / intermediates / manifests / full / debug / AndroidManifest.xml:25:AAPT:error :找到未知元素 。在我将其放入应用程序标记后,该项目已成功编译。就这样