[关闭]
@act262 2017-08-10T13:05:08.000000Z 字数 1378 阅读 993

升级到 Gradle plugin 2.3.0出现的问题

gradle


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

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

输出如下log

  1. ...
  2. ERROR: Unable to open PNG file
  3. 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
  4. Error: Some file crunching failed, see logs for details
  5. :app:mergeProdReleaseResources FAILED
  6. FAILURE: Build failed with an exception.
  7. * What went wrong:
  8. Execution failed for task ':app:mergeProdReleaseResources'.
  9. > Error: Some file crunching failed, see logs for details
  10. * Try:
  11. 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文件设置
  1. // You can specify either an absolute path or a path relative
  2. // to the gradle.properties file.
  3. // 1. 指定build-cache路径
  4. android.buildCacheDir=<path-to-directory>
  5. // To re-enable the build cache, either delete the following
  6. // line or set the property to 'true'.
  7. // 2. 禁用缓存功能
  8. android.enableBuildCache=false

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

  1. ./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

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注