之前编译EasyPusher-Android版程序是没问题的,最近又拿出来调试,发现编译不过去了:
针对AAPT2 error这个错误,网上给出的解决方案种类还是蛮多的,说的最多的是在gradle.properties中加入一行代码:
android.enableAapt2=false
但这个在Android Studio3.2版本上无效,还有说找到layout文件夹下后缀为.9png的图片,删掉,然而我这个项目没有这个文件。但是看到build.gradle文件下有个画红线的行:
好像提到了版本不一致的问题,仔细核查一下SDK的版本:
而几个support包的版本也都是27的:
这个项目也没有其他的Module,问题再一度陷入了僵局,只能尝试删除build目录,清缓存:
虽然网上有这么解决问题的,但是遗憾的是我这里不行。没办法,这么瞎试不能解决问题,只能静下心自己分析日志了:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':app:processRtspDebugResources'.
at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:100)
...
Caused by: org.gradle.tooling.BuildException: Failed to execute aapt
看日志是这个processRtspDebugResources任务出现了异常,那么就单独执行这个任务,看其详细日志:
日志如下:
:app:splitsDiscoveryTaskRtspDebug UP-TO-DATE
AGPBI: {"kind":"error","text":"error: resource android:attr/dialogCornerRadius not found.","sources":[{"file":"F:\\AndroidStudio-SDK\\.gradle\\caches\\transforms-1\\files-1.1\\appcompat-v7-28.0.0.aar\\25460ff3889b39e0bda8a23e830d00bc\\res\\values-v28\\values-v28.xml","position":{"startLine":8,"startColumn":4,"startOffset":447,"endLine":11,"endColumn":12,"endOffset":684}}],"original":"","tool":"AAPT"}
AGPBI: {"kind":"error","text":"error: resource android:attr/dialogCornerRadius not found.","sources":[{"file":"E:\\AndroidWorkSpace\\EasyPusher-master\\app\\build\\intermediates\\incremental\\mergeRtspDebugResources\\merged.dir\\values-v28\\values-v28.xml","position":{"startLine":10}}],"original":"","tool":"AAPT"}
AGPBI: {"kind":"error","text":"error: resource android:attr/fontVariationSettings not found.","sources":[{"file":"F:\\AndroidStudio-SDK\\.gradle\\caches\\transforms-1\\files-1.1\\appcompat-v7-28.0.0.aar\\25460ff3889b39e0bda8a23e830d00bc\\res\\values\\values.xml","position":{"startLine":1303,"startColumn":4,"startOffset":70911,"endColumn":68,"endOffset":70975}}],"original":"","tool":"AAPT"}
AGPBI: {"kind":"error","text":"error: resource android:attr/ttcIndex not found.","sources":[{"file":"F:\\AndroidStudio-SDK\\.gradle\\caches\\transforms-1\\files-1.1\\appcompat-v7-28.0.0.aar\\25460ff3889b39e0bda8a23e830d00bc\\res\\values\\values.xml","position":{"startLine":1303,"startColumn":4,"startOffset":70911,"endColumn":68,"endOffset":70975}}],"original":"","tool":"AAPT"}
E:\AndroidWorkSpace\EasyPusher-master\app\build\intermediates\incremental\mergeRtspDebugResources\merged.dir\values-v28\values-v28.xml:7: error: resource android:attr/dialogCornerRadius not found.
...
Caused by: com.android.tools.aapt2.Aapt2Exception: AAPT2 error: check logs for details
仔细分析发现日志里面有appcompat-v7-28.0.0.aar内容,为什么会用到appcompat-v7-28.0.0呢?明明指定的是appcompat-v7:27.1.1,再仔细检查gradle.properties文件:
这有个用最新版本的包,这个里面肯定用到了compileSdkVersion 28版本,赶紧改成一个指定的版本:
改后还是报错呢?原来constraint-layout包也没有指定版本:
把+改成1.1.2版本:
再编译就不报错了,项目不能总用最新版本的SDK来重新编译啊。看来指定对应包的版本是多么的重要!要不过一段时间编译出错都不知道怎么回事。