NOTICE:请不要发布此内容“android.enableAapt2 = false”作为答案。这是not一个办法。它只是忽略真正的错误,不会在运行时造成任何问题。
解决办法很简单,只要去掉错误放置的即可动作标签在清单文件中的意图过滤器之外。
有一个由 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" />
如果我评论/删除此操作标记行,该项目可以正常构建,但这是必要的GCM
我无法删除它。
正如您看到的日志,错误不会出现在 main 处清单文件,位于 /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.
要解决此问题,请确保清单元素正确嵌套。欲了解更多信息,请阅读清单文件结构.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)