Error:Execution failed for task ':app:processDebugResources'

爆出錯誤 Error:Execution failed for task ':app:processDebugResources'.
> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'F:\Android\SDK\build-tools\**.*.*\aapt.exe'' finished with non-zero exit value 1

定位錯誤 在android studio terminal 終端輸入以下命令

gradlew processDebugResources --debug


從打印出的log中 鎖定error錯誤信息 18:39:47.014 [ERROR] [org.gradle.api.Project] \\?\C:\Users\****\Pro\app\build\intermediates\merged_manifests\debug\processDebugManifest\merged\AndroidManifest.xml:27: AAPT: No resource ident
ifier found for attribute 'appComponentFactory' in package 'android'
沒有在 'android' 包中找到 'appComponentFactory '這個屬性(沒有相關資源是不是少導入了一些什麼?)
【Error:Execution failed for task ':app:processDebugResources'】
解決對策: 不太清楚具體原因的情況下:
習慣性的cleanrebuildrestart三個動作來一下
依舊沒有解決:
百度谷歌相關問題的解決對策進行參考并測試其是否能解決自己的問題
找到符合自己的最佳答案:
在build.gradle 下allprojects 添加一下信息, 問題得到解決

  • configurations.all { resolutionStrategy.force 'com.android.support:support-v4:24.0.0' }

    這句起來什麼作用?
涉及gradle 首先查看gradle文檔https://docs.gradle.org/current/dsl/org.gradle.api.artifacts.ResolutionStrategy.html
找到 關鍵字API:ResolutionStrategy
英文定義:
Defines the strategies around dependency resolution. For example, forcing certain dependency versions, substitutions,conflict resolutions or snapshot timeouts.
谷歌翻譯:定義依賴解析的策略。例如,強制某些依賴項版本,替換,衝突解決方案或快照超時
Examples:
pply plugin: 'java' //so that there are some configurationsconfigurations.all { resolutionStrategy { // fail eagerly on version conflict (includes transitive dependencies) // e.g. multiple different versions of the same dependency (group and name are equal) failOnVersionConflict()// prefer modules that are part of this build (multi-project or composite build) over external modules preferProjectModules()// force certain versions of dependencies (including transitive) //*append new forced modules: force 'asm:asm-all:3.3.1', 'commons-io:commons-io:1.4' //*replace existing forced modules with new ones: forcedModules = ['asm:asm-all:3.3.1']// add dependency substitution rules dependencySubstitution { substitute module('org.gradle:api') with project(':api') substitute project(':util') with module('org.gradle:util:3.0') }// cache dynamic versions for 10 minutes cacheDynamicVersionsFor 10*60, 'seconds' // don't cache changing modules at all cacheChangingModulesFor 0, 'seconds' } }

文檔還有一些其他的API及例子就不一一介紹,自行查看
從例子可以看到
force certain versions of dependencies (including transitive)強制某些版本的依賴項
resolutionStrategy.force 'com.android.support:support-v4:24.0.0'

作用:使你的項目強制依賴于com.android.support:support-v4:24.0.0
結論:我的項目com.android.support:support-v4:24.0.0 版本有問題或不存在才導致出現問題的




    推荐阅读