注意事项:请勿将此"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
发布于 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。
发布于 2017-10-30 17:06:54
在根项目的gradle.properties中添加以下代码:
android.enableAapt2=false
这对我很有效
root
|
|--gradle.properties
发布于 2018-06-01 20:20:15
根据Manifest file structure将操作内容放入intent-filter中,如下所示。
<intent-filter>
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
</intent-filter>
https://stackoverflow.com/questions/46948498
复制相似问题