Android Studio重建应用时遇generatedPngsOutputDir=null错误求助
Hey, I’ve run into this exact error before when rebuilding Android Studio projects—total headache, right? Let’s walk through the fixes that worked for me and other developers in the community:
Clean, Rebuild, and Wipe Gradle Cache
Start with the basics—sometimes stale build files are the culprit:- In Android Studio, go to
Build > Clean Project - Then run
Build > Rebuild Project - If that doesn’t work, close Android Studio and manually delete:
- The
.gradlefolder in your project root - The
buildfolders in both your project root and each individual module
- The
- Restart Android Studio and let it re-sync your Gradle files
- In Android Studio, go to
Fix Vector Drawables Configuration
This error is often tied to vector drawable generation settings. Double-check your module-levelbuild.gradle(orbuild.gradle.ktsfor Kotlin projects) under theandroidblock:
For Groovy:android { // ... other existing configs buildFeatures { vectorDrawables true } vectorDrawables { generatedDensities = [] useSupportLibrary = true // Skip this if you're using AndroidX instead of support libraries } }For Kotlin DSL:
android { // ... other existing configs buildFeatures { vectorDrawables = true } vectorDrawables { generatedDensities = emptyList() useSupportLibrary = true // Adjust based on your dependency setup } }Note: Even though
generatedDensitiesis deprecated in AGP 7.0+, setting it to an empty list still resolves this null directory issue for many projects.Ensure Gradle & AGP Version Compatibility
Mismatched versions between Gradle and the Android Gradle Plugin (AGP) often cause weird null-value errors. Use compatible versions:- Open
File > Project Structure > Projectin Android Studio - Let the IDE auto-select a Gradle version that matches your AGP version (e.g., AGP 8.0+ needs Gradle 8.0+, AGP 7.4 works with Gradle 7.5+)
- Apply the changes and sync your project
- Open
Check for Invalid gradle.properties Settings
Open your project’sgradle.propertiesfile and look for any lines related togeneratedPngsOutputDiror vector drawable generation. If you see a line likeandroid.defaultConfig.vectorDrawables.generatedPngsOutputDir=null, delete it—invalid values here can trigger the error.Invalidate IDE Caches & Restart
Corrupted IDE caches are another common culprit:- Go to
File > Invalidate Caches... - Select "Invalidate and Restart"
- Let Android Studio restart and rebuild your project from scratch
- Go to
If none of these fixes work, try creating a new empty Android project and gradually migrate your code/resources over. Sometimes project configuration files get irreparably corrupted, and a fresh start is the fastest solution.
内容的提问来源于stack exchange,提问作者Roboman Robo

