首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >Android Studio3.0清单错误:找到未知元素<action>

Android Studio3.0清单错误:找到未知元素<action>
EN

Stack Overflow用户
提问于 2017-10-26 15:43:44
回答 8查看 66.4K关注 0票数 45

注意事项:请勿将此"android.enableAapt2=false"作为答案发布。这是而不是解决方案。它只是忽略了真正的错误,这在运行时不会造成任何问题。

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

我有一个由Android Studio 2.3构建的应用程序。更新Android Studio3.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>

Error显示以下行:

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

如果我注释/删除此操作标记行,项目构建正常,但它是GCM所必需的,并且我无法删除它。

正如您在日志中看到的那样,在/build/intermediates/manifests/full/debug/AndroidManifest.xml上出现错误not occurs at main manifest file

已尝试清理、重建和禁用即时运行。有什么解决方案吗?

错误日志:

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

回答 8

Stack Overflow用户

回答已采纳

发布于 2017-10-26 15:47:06

您有一个放错位置的标签。新的AAPT (AAPT2)现在在这方面抛出一个错误。

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

使用AAPT2时

行为发生变化

为了提高增量资源处理能力,Android plugin 3.0.0默认开启AAPT2。尽管AAPT2应该立即使用较旧的项目,但本节介绍了您应该注意的一些行为更改。

Android清单中的元素层次结构

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

<应用程序...

以前版本的AAPT会简单地忽略放错位置的标签。但是,使用AAPT2时,您会得到以下错误:

AndroidManifest.xml:15:错误:找到未知元素。

若要解决此问题,请确保正确嵌套清单元素。有关更多信息,请阅读Manifest file structure

票数 40
EN

Stack Overflow用户

发布于 2017-10-30 17:06:54

项目的gradle.properties中添加以下代码:

android.enableAapt2=false

这对我很有效

root 
| 
|--gradle.properties
票数 16
EN

Stack Overflow用户

发布于 2018-06-01 20:20:15

根据Manifest file structure将操作内容放入intent-filter中,如下所示。

<intent-filter>
        <action android:name="com.google.android.c2dm.intent.REGISTRATION" />
 </intent-filter>
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46948498

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档