升级到 Gradle plugin 2.3.0出现的问题

升级到 Gradle plugin 2.3.0出现的问题

Tags: gradle


自从把gradle plugin升级到2.3.0后出现了问题,3.0.0后又没有这个问题了。
本地AS或者命令行跑都没有出现问题,但是在CI服务器上跑的却出现问题了。

CI服务器上的一些环境变量可能被某个软件改变了,所以默认用户目录不是我们的

输出如下log

...
ERROR: Unable to open PNG file
AAPT err(Facade for 2005761187): \\?\C:\Windows\System32\config\systemprofile\.android\build-cache\a08444405a12f3ce2f6e1175b4b52105017305cd\output\res\drawable-xhdpi-v4\abc_spinner_mtrl_am_alpha.9.png ERROR: Unable to open PNG file
Error: Some file crunching failed, see logs for details
:app:mergeProdReleaseResources FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:mergeProdReleaseResources'.
> Error: Some file crunching failed, see logs for details

* Try:
Run with --info or --debug option to get more log output.

大概就是说文件目录不能识别导致的问题了,有可能是目录太长,也有可能是编码问题导致的.
在gradle3.x之后有缓存功能,而android gradle plugin 2.3.0默认开启了build-cache功能,可以加速构建的。

解决方案

  1. 指定正常的build-cache路径,默认在~/.android/build-cache
  2. 禁用这个缓存功能
    在gradle.properties文件设置
// You can specify either an absolute path or a path relative
// to the gradle.properties file.
// 1. 指定build-cache路径
android.buildCacheDir=<path-to-directory>

// To re-enable the build cache, either delete the following
// line or set the property to 'true'.
// 2. 禁用缓存功能
android.enableBuildCache=false

也可以在gradle命令后跟上参数

 ./gradlew assembleDebug -Pandroid.enableBuildCache=false

参考:

https://developer.android.com/studio/build/build-cache.html
https://stackoverflow.com/questions/42580645/errorsome-file-crunching-failed-see-logs-for-details-afer-update-gradle

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 176,507评论 25 709
  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 136,174评论 19 139
  • Gradle plugin 3.0 & Android Studio 3.0 我们主要讲一下升级gradle pl...
    coofee阅读 18,627评论 6 17
  • 现在说到免费的课程别人还不愿意学习,难道真的变成了要付费才有人学习的境地吗。随着网络时代,特别是互联网和移动互联网...
    麦风玄阅读 1,693评论 0 1
  • 教育学生,作为一个班级的班主任,首先应认识到他们既是整体,又是一个个鲜活的个体,充分发挥每一个孩子...
    朵以阅读 3,823评论 0 4

友情链接更多精彩内容