Process 'command 'F:\sdk\build-tools\26.0.2\aapt.exe'' finished with non-zero exit value 1

时间:2021-04-01 23:03:04

AndroidStudio升级到3.0新建一个项目,导入github上面的一个项目报错。

AndroidStudio升级到3.0新建一个项目,导入github上面的一个项目报错。导入的项目是

compile 'com.youth.xframe:xframe:1.1.2'

结果就报错了,具体错误如下

C:\Users\cb\.gradle\caches\transforms-1\files-1.1\appcompat-v7-28.0.0-alpha1.aar\770b215e14f9b86c9aafbabc6da9a7f1\res\values-v26\values-v26.xml
Error:(15, 21) No resource found that matches the given name: attr 'android:keyboardNavigationCluster'.
Error:java.util.concurrent.ExecutionException: com.android.ide.common.process.ProcessException: Error while executing process F:\sdk\build-tools\26.0.2\aapt.exe with arguments {package -f --no-crunch -I F:\sdk\platforms\android-25\android.jar -M \\?\F:\studioworkpalce\HomeCareB\app\build\intermediates\manifests\full\debug\AndroidManifest.xml -S F:\studioworkpalce\HomeCareB\app\build\intermediates\res\merged\debug -m -J \\?\F:\studioworkpalce\HomeCareB\app\build\generated\source\r\debug -F F:\studioworkpalce\HomeCareB\app\build\intermediates\res\debug\resources-debug.ap_ --custom-package com.sctel.app.homecareandroid_b -0 apk --output-text-symbols \\?\F:\studioworkpalce\HomeCareB\app\build\intermediates\symbols\debug --no-version-vectors}
Error:org.gradle.process.internal.ExecException: Process 'command 'F:\sdk\build-tools\26.0.2\aapt.exe'' finished with non-zero exit value 1
F:\studioworkpalce\HomeCareB\app\build\intermediates\res\merged\debug\values-v26\values-v26.xml
Error:Execution failed for task ':app:processDebugResources'.
> Failed to execute aapt
Error:(13, 5) No resource found that matches the given name: attr 'android:keyboardNavigationCluster'.
Error:com.android.ide.common.process.ProcessException: Error while executing process F:\sdk\build-tools\26.0.2\aapt.exe with arguments {package -f --no-crunch -I F:\sdk\platforms\android-25\android.jar -M \\?\F:\studioworkpalce\HomeCareB\app\build\intermediates\manifests\full\debug\AndroidManifest.xml -S F:\studioworkpalce\HomeCareB\app\build\intermediates\res\merged\debug -m -J \\?\F:\studioworkpalce\HomeCareB\app\build\generated\source\r\debug -F F:\studioworkpalce\HomeCareB\app\build\intermediates\res\debug\resources-debug.ap_ --custom-package com.sctel.app.homecareandroid_b -0 apk --output-text-symbols \\?\F:\studioworkpalce\HomeCareB\app\build\intermediates\symbols\debug --no-version-vectors}

乍眼一看,初步断定是attr的缺少了自定义属性,但是在项目里死活没有找到类似的自定义属性,于是上网找,看看有没有类似的问题,还真是找到了很多。下面我就说说怎么解决这个问题的吧。

首先关闭了AAPT2

在gradle.properties中添加下面代码,重新编译下

android.enableAapt2=false

Process 'command 'F:\sdk\build-tools\26.0.2\aapt.exe'' finished with non-zero exit value 1

如果还未解决,我们接着看

在仔细看下错误日志,发现是找不到v7 28.0.0下面的资源文件,但是我项目使用的v7包是26.0.1的,为什么会报找不到v7 28.0.0下面的资源文件呢,那肯定就是导入的依赖库造成的,我就去下载xframe源码结果发现在xframe的build.gradle下引入的高版本的v7包如下图
Process 'command 'F:\sdk\build-tools\26.0.2\aapt.exe'' finished with non-zero exit value 1

这就很好理解了为什么会报错了,主程序是26的v7包,而依赖库是最新的v7包(也就是28的)导致两边的v7包版本不一致导致编译失败,但是依赖库是改不了得大多数人也不会去下载源码改,所以只有在app得build.gradler下面加段代码统一下库版本就可以,需要加载build得最下面,大括号外面。重新编译。代码如下

configurations.all {
    resolutionStrategy.eachDependency { details -> def requested = details.requested
        if (requested.group == 'com.android.support') {
            if (!requested.name.startsWith("multidex")) {
            //这里写你想统一的版本是多少,前提是你sdk里有
                details.useVersion '25.0.0'
            }
        }
    }
}

Process 'command 'F:\sdk\build-tools\26.0.2\aapt.exe'' finished with non-zero exit value 1

如果还是未能解决你的问题,留言我会帮你看看。