File xxx specified for property 'resourceFile' does not exist.

本文介绍了一种常见的Gradle打包失败问题,即指定的资源文件不存在导致的任务配置错误,并提供了解决方案,通过调整构建脚本中的shrinkResources属性来避免此类错误。

Error:A problem was found with the configuration of task ':app:packageDebug'.

> File xxx specified for property 'resourceFile' does not exist.



解决方法:将shrinkResource设置为false

buildTypes {
        release {
            // 不显示Log
            buildConfigField "boolean", "LOG_DEBUG", "false"
            //混淆
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            //Zip代码压缩优化
            zipAlignEnabled true
            //移除无用资源
            shrinkResources false
            signingConfig signingConfigs.release
        }
        debug {
            //Zip代码压缩优化
            zipAlignEnabled true
            //移除无用资源
            shrinkResources false
            signingConfig signingConfigs.release
            minifyEnabled false
        }
    }

在 Gradle 构建过程中,出现 **"distribution URL is invalid or does not exist"** 错误通常意味着 `gradle-wrapper.properties` 文件中指定的 Gradle 分发包地址无效或无法访问。该文件通常位于 `gradle/wrapper/gradle-wrapper.properties` 路径下。 ### 常见原因及解决方法 #### 1. 检查 `distributionUrl` 的配置 确保 `distributionUrl` 的值正确无误,格式应为: ```properties distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip ``` 注意: - URL 必须以 `https://` 开头。 - Gradle 官方的分发地址是 `https://services.gradle.org/distributions/`。 - 确保版本号正确且该版本确实存在。 #### 2. 使用有效的 Gradle 版本 Gradle 的版本必须存在于官方服务器上。可以访问 [Gradle 发布页面](https://services.gradle.org/distributions/) 查看所有可用版本。 例如,如果希望使用 Gradle 7.4,则应使用以下 URL: ```properties distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip ``` #### 3. 网络问题或代理配置 如果构建环境无法访问外部网络,则可能导致无法下载 Gradle 分发包。可以尝试: - 检查网络连接。 - 配置代理(如果需要),在 `gradle.properties` 中添加: ```properties systemProp.http.proxyHost=proxy.example.com systemProp.http.proxyPort=8080 systemProp.https.proxyHost=proxy.example.com systemProp.https.proxyPort=8080 ``` #### 4. 使用本地 Gradle 分发包 如果无法从网络下载,可以手动下载 Gradle 分发包并放置在本地路径中,然后修改 `gradle-wrapper.properties` 文件如下: ```properties distributionUrl=file:///opt/gradle/gradle-7.4-bin.zip ``` 确保路径在构建环境中有效。 #### 5. 使用 `--gradle-version` 参数更新 Wrapper 可以使用 Gradle 命令行工具更新当前项目使用的 Gradle 版本: ```bash ./gradlew wrapper --gradle-version 7.4 ``` 这将自动更新 `gradle-wrapper.properties` 中的 `distributionUrl`。 --- ### 示例:更新 `gradle-wrapper.properties` 文件 ```properties # gradle/wrapper/gradle-wrapper.properties distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists distributionUrl=https\://services.gradle.org/distributions/gradle-7.4-bin.zip ``` --- ### 注意事项 - Gradle Wrapper 是推荐的使用方式,因为它确保所有开发者使用相同的 Gradle 版本。 - 如果使用 CI/CD 环境,确保其能够访问 `distributionUrl` 所指定的地址。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值