Android打包报错:Entry name 'META-INF...'冲突问题求助
Hey there! This collision error is super common when adding third-party SDKs (like ads) to your project—here’s how to fix it step by step:
Why this happens
The error means multiple dependencies in your project (your core app code + the new ad SDK you added) are including the same androidx.vectordrawable version metadata file. When Android Studio tries to package the APK, it hits a duplicate entry and crashes.
Solution 1: Exclude duplicate dependencies from the ad SDK
First, identify which dependency is bringing in the duplicate vectordrawable library. Run this command in your project root to see the full dependency tree:
./gradlew app:dependencies
Look for entries related to androidx.vectordrawable:vectordrawable or androidx.vectordrawable:vectordrawable-animated that appear multiple times (once from your project, once from the ad SDK).
Then, exclude the duplicate from your ad SDK implementation in your app’s build.gradle (Module level):
implementation('com.google.android.gms:play-services-ads:22.4.0') { // Replace with your ad SDK version exclude group: 'androidx.vectordrawable', module: 'vectordrawable' exclude group: 'androidx.vectordrawable', module: 'vectordrawable-animated' }
Solution 2: Force a unified version for all dependencies
If excluding doesn’t work, you can force every dependency in your project to use the same vectordrawable version. Add this to your project’s root build.gradle file:
dependencyResolutionManagement { versions { androidxVectordrawable = "1.1.0" // Use the stable version your project already uses } resolutionStrategy { force "androidx.vectordrawable:vectordrawable:$androidxVectordrawable" force "androidx.vectordrawable:vectordrawable-animated:$androidxVectordrawable" } }
Solution 3: Clean up caches and rebuild
Sometimes stale cache files cause weird packaging issues. Do a full clean:
- Go to
File > Invalidate Caches...in Android Studio, then selectInvalidate and Restart - Or run these commands in your terminal:
./gradlew clean ./gradlew assembleDebug
Quick check for animation-list resources
While the error points to a version file collision, double-check your new animation-list drawables to make sure they don’t have duplicate filenames or invalid XML syntax—though this is less likely to cause this specific error, it’s good to rule out.
内容的提问来源于stack exchange,提问作者Álvaro Sánchez

