1 背景
整合同事寫的代碼時,由於修改了package名稱,需要修改大量文件,修改完成後,build報錯:
AAPT2 error: check logs for details
2 解決
在terminal中輸入:
gradlew compileDebug --stacktrace
報錯信息如下:
FAILURE: Build failed with an exception.
* What went wrong:
Task 'compileDebug' is ambiguous in root project 'XXXXX'. Candidates are: 'compileDebugAidl', 'compileDebugAndroidTestAidl', 'compileDebugAndroidTestJavaWithJavac', 'compileDebugAndroidTestNdk', 'compil
eDebugAndroidTestRenderscript', 'compileDebugAndroidTestShaders', 'compileDebugAndroidTestSources', 'compileDebugJavaWithJavac', 'compileDebugNdk', 'compileDebugRenderscript', 'compileDebugShaders', 'compil
eDebugSources', 'compileDebugUnitTestJavaWithJavac', 'compileDebugUnitTestSources'.
* Exception is:
org.gradle.execution.TaskSelectionException: Task 'compileDebug' is ambiguous in root project 'XXXx'. Candidates are: 'compileDebugAidl', 'compileDebugAndroidTestAidl', 'compileDebugAndroidTestJavaWith
Javac', 'compileDebugAndroidTestNdk', 'compileDebugAndroidTestRenderscript', 'compileDebugAndroidTestShaders', 'compileDebugAndroidTestSources', 'compileDebugJavaWithJavac', 'compileDebugNdk', 'compileDebug
Renderscript', 'compileDebugShaders', 'compileDebugSources', 'compileDebugUnitTestJavaWithJavac', 'compileDebugUnitTestSources'.
這時輸入命令:
gradlew compileDebugJavaWithJavac
mac 命令
./gradlew compileDebugJavaWithJavac
結果如下
D:\Android_projects\XXXXXxn\app\build\intermediates\manifests\full\debug\AndroidManifest.xml:85: AAPT: error: unknown element <intent-filter> found.
提示清單文件的標籤有誤,找到該路徑下的清單,果然有問題:
缺少了一個結束的標籤。
對應的時app module下Androidmanifest.xml修改完成即可
注意:
AAPT2 error: check logs for details 這個報錯一般就是資源文件或者xml的文件格式有錯誤。