Android Studio 3.0清单错误:未知元素< action>成立 [英] Android Studio 3.0 Manifest Error: unknown element <action> found

查看:175
本文介绍了Android Studio 3.0清单错误:未知元素< action>成立的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

注意:请不要发布此"android.enableAapt2 = false" 作为答案.这不是不是解决方案.它只是忽略了不会在运行时引起任何问题的实际错误.

解决方案很简单,只需删除清单文件中意图过滤器外部错误放置的 action标签即可.

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

这是我的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>

错误显示此行:

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

如果我评论/删除此动作标签行,则该项目可以正常运行,但对于GCM是必需的,而我无法删除它.

如您所见,日志未在主清单文件中发生,在/build/intermediates/manifests/full/debug/AndroidManifest.xml中发生了错误 >

尝试清洁,重建,禁用即时运行.有什么解决办法吗?

错误日志:

/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

解决方案

标签位置错误.现在,新的AAPT(AAPT2)对此引发了错误.

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

使用AAPT2时的行为发生变化


为改善增量资源处理,默认情况下,Android插件3.0.0启用AAPT2.尽管AAPT2应该可以立即用于较早的项目,但本节将介绍一些您应该注意的行为更改.

Android清单中的元素层次结构

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

以前版本的AAPT只会忽略放错位置的标签.但是,对于AAPT2,您会收到以下错误:

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

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

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.

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

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.

Here my 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.

As you see the logs, The error not occurs at main manifest file, occurs at /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

解决方案

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

From the docs in here: 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.

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:

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

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.

这篇关于Android Studio 3.0清单错误:未知元素&lt; action&gt;成立的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆