You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Gradle编译正常但图片资源异常问题咨询

解决Gradle编译时图片资源未被正确打包的问题

Hey there, let's figure out why your PNG images aren't making it into the build while CSS files work perfectly.

Looking at your build.gradle config, the root cause is in how you've configured the resource includes. You're setting the includes property twice:

includes = ["**/*.png"]
includes = ["**/*.css"]

Each time you use the assignment operator =, you're replacing the entire list of included files instead of adding to it. That means only the last pattern (**/*.css) is actually being applied—so your PNGs are getting ignored entirely.

Fixes you can apply

There are two straightforward ways to fix this:

  1. Combine both patterns into a single includes list
    Update your sourceSets block to include both file types in one line:

    sourceSets {
        main {
            resources {
                srcDirs = ["src/main/java"]
                includes = ["**/*.png", "**/*.css"]
            }
        }
    }
    
  2. Use include (singular) multiple times
    If you prefer more readable, line-by-line configuration, use the singular include method to add each file type separately:

    sourceSets {
        main {
            resources {
                srcDirs = ["src/main/java"]
                include "**/*.png"
                include "**/*.css"
            }
        }
    }
    

After making either change, run gradle clean build to clear any old build artifacts and ensure the new resources are properly packaged with your compiled code. That should get your PNGs working alongside the CSS files!

内容的提问来源于stack exchange,提问作者Ceylon Boy

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.21 06:26:37