Android Studio 3.0 Manifest Error: unknown element <action> found
Android Studio 3.0 Manifest 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.
有一个由 Android Studio 2.3 构建的应用程序很好。
更新 Android Studio 3.0 Stable 后,开始出现此错误并且无法构建我的项目。
这是我的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" />
如果我 comment/remove 这个动作标记行,项目构建良好,但它是 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
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.
在gradle.properties中添加这段代码在root项目中:
android.enableAapt2=false
这对我有用
root
|
|--gradle.properties
为了总结和简化:你应该只专注于你的主 AndroidManifest.xml 文件并检查它是否严格遵循顺序以及 XML 标签的嵌套,如 [=10] 中所述=].否则 IDE 将打开调试级别 AndroidManifest.xml,每次尝试 clean/build 项目时都会显示大量错误,让您感到困惑!
只需像这样重命名您的清单文件:AndroidManifest.xmlold,然后创建一个新的 XML 文件并命名为:AndoridManifest.xml。然后在删除带有标记的行后复制旧文件的内容。 Build>Clean Project 然后 运行>debug app 再次。那么问题就会消失。
我们有这个问题的解决方案,解决方案是服务始终属于 <Application <service>>
的子形式
当我们在 <Application>
之外编写代码时,就会出现问题。服务是清单中应用程序的子部分......
好的...它一定会起作用..做它
将操作内容放入 intent-filter 中,如下所示
<intent-filter>
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
</intent-filter>
在我的应用程序中,AndroidManifest.xml 标记接收器位于应用程序标记下,这是构建失败并显示消息 .../android/app/build/intermediates/manifests/full/debug/AndroidManifest.xml:25: AAPT: error: unknown element <receiver> found
的原因。在我把它放在应用程序标签中之后,项目就编译成功了。就这些了
我最近对我的 gradle.properties 进行了此修复,但警告说 "The option 'android.enableAapt2' is deprecated..." 不断出现,解决方案是将其更改为 true。
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.
有一个由 Android Studio 2.3 构建的应用程序很好。 更新 Android Studio 3.0 Stable 后,开始出现此错误并且无法构建我的项目。
这是我的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" />
如果我 comment/remove 这个动作标记行,项目构建良好,但它是 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
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.
在gradle.properties中添加这段代码在root项目中:
android.enableAapt2=false
这对我有用
root
|
|--gradle.properties
为了总结和简化:你应该只专注于你的主 AndroidManifest.xml 文件并检查它是否严格遵循顺序以及 XML 标签的嵌套,如 [=10] 中所述=].否则 IDE 将打开调试级别 AndroidManifest.xml,每次尝试 clean/build 项目时都会显示大量错误,让您感到困惑!
只需像这样重命名您的清单文件:AndroidManifest.xmlold,然后创建一个新的 XML 文件并命名为:AndoridManifest.xml。然后在删除带有标记的行后复制旧文件的内容。 Build>Clean Project 然后 运行>debug app 再次。那么问题就会消失。
我们有这个问题的解决方案,解决方案是服务始终属于 <Application <service>>
的子形式
当我们在 <Application>
之外编写代码时,就会出现问题。服务是清单中应用程序的子部分......
好的...它一定会起作用..做它
<intent-filter>
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
</intent-filter>
在我的应用程序中,AndroidManifest.xml 标记接收器位于应用程序标记下,这是构建失败并显示消息 .../android/app/build/intermediates/manifests/full/debug/AndroidManifest.xml:25: AAPT: error: unknown element <receiver> found
的原因。在我把它放在应用程序标签中之后,项目就编译成功了。就这些了
我最近对我的 gradle.properties 进行了此修复,但警告说 "The option 'android.enableAapt2' is deprecated..." 不断出现,解决方案是将其更改为 true。