集成特定库后Gradle构建报错:Program type already present异常
Hey there, let's fix that frustrating Gradle build error you're dealing with! That "Program type already present" message tells us your project has duplicate copies of the same class—in this case, com.nostra13.universalimageloader.cache.disc.impl.ext.DiskLruCache$1 from Universal Image Loader (UIL). Here's how to resolve it step by step:
First, we need to pinpoint which library is bringing in an extra copy of UIL. Run this command in your project root (or use Android Studio's built-in Gradle tooling):
./gradlew app:dependencies
Or in Android Studio:
- Open the Gradle sidebar (usually on the right-hand side)
- Navigate to your app module > Tasks > android > androidDependencies
- Run that task, then search the output for "universal-image-loader"
You’ll see two entries for UIL: one you added explicitly, and another from a third-party library—that’s the duplicate causing the conflict.
Once you’ve identified the problematic library, add an exclusion rule to your module-level build.gradle file. For example, if the conflicting library is com.example.thirdparty:somelib:2.0.0, update its dependency entry like this:
implementation('com.example.thirdparty:somelib:2.0.0') { exclude group: 'com.nostra13.universalimageloader', module: 'universal-image-loader' }
This tells Gradle to keep only the UIL version you explicitly added, discarding the duplicate copy from the third-party library.
It’s also possible you accidentally added UIL multiple times in your dependencies block. Scan for lines like:
implementation 'com.nostra13.universalimageloader:universal-image-loader:1.9.5'
Make sure there’s only one entry for UIL, and use the latest stable version if possible.
After adjusting your dependencies, don’t skip this critical step—old build cache can still cause conflicts:
- Go to Build > Clean Project in Android Studio
- Then run Build > Rebuild Project
This ensures Gradle uses your updated dependency configuration instead of cached files.
Universal Image Loader is no longer actively maintained. If you want to avoid these kinds of dependency conflicts long-term, switching to libraries like Glide or Picasso is a smart move—they’re faster, better supported, and less likely to clash with other project dependencies.
内容的提问来源于stack exchange,提问作者Vikram Bhatt

