More than one file was found with OS independent path "META-INF/LICENSE"

Matheus Mello
Matheus Mello
September 2, 2023
Cover Image for More than one file was found with OS independent path "META-INF/LICENSE"

📝 Blog Post: How to Fix the "More than one file was found with OS independent path 'META-INF/LICENSE'" Error in Android Build 📱💥

Have you ever encountered the frustrating error "Execution failed for task ':app:transformResourcesWithMergeJavaResForDebug'. More than one file was found with OS independent path 'META-INF/LICENSE'" while building your Android app? 😫

Fear not! In this blog post, we will dive into this common issue and provide you with easy solutions to get rid of this error. Let's get started! 🚀

Understanding the Problem

The error message indicates that there are multiple files with the same path 'META-INF/LICENSE' in your app's resources. This can cause conflicts during the build process, resulting in the error. The good news is, we can easily solve this issue with a couple of tweaks. 💪

Solution 1: Configuring packagingOptions

One way to resolve this error is by excluding the duplicate files using the packagingOptions block in your app's build.gradle file. Here's an example:

android {
   // ...

   packagingOptions {
       exclude 'META-INF/DEPENDENCIES'
       exclude 'META-INF/NOTICE'
       exclude 'META-INF/LICENSE'
       exclude 'META-INF/LICENSE.txt'
       exclude 'META-INF/NOTICE.txt'
   }
}

By adding these exclude directives, you are instructing the build system to ignore duplicate files when merging resources.

Problem: Another Issue Arises

However, please note that excluding certain files in the packagingOptions may lead to other issues, as mentioned by one of our readers. They faced the java.lang.NoClassDefFoundError: com.squareup.leakcanary.internal.HeapAnalyzerService error after excluding the duplicate files.

Solution 2: Adjust Dependencies

To fix this new error, you need to make sure the required dependencies are included in your app. In this case, the missing class com.squareup.leakcanary.internal.HeapAnalyzerService can be resolved by adding the following dependencies to your build.gradle file:

dependencies {
    // ...

    debugCompile 'com.squareup.leakcanary:leakcanary-android:1.5.1'
    releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.5.1'
    testCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.5.1'
}

Make sure to sync your project after adding these dependencies to resolve the NoClassDefFoundError issue.

Conclusion

By following the steps mentioned in this blog post, you should be able to fix the "More than one file was found with OS independent path 'META-INF/LICENSE'" error in your Android build. Remember to exclude duplicate files using the packagingOptions block and adjust your dependencies accordingly to avoid any new issues.

We hope this guide helped you overcome this annoying error! 🎉 If you have any other questions or facing any other tech-related challenges, feel free to reach out. Let's keep building amazing apps together! 👩‍💻👨‍💻

Don't forget to share this post with your fellow developers who might be struggling with this error. Sharing is caring! ❤️ Happy coding!

Take Your Tech Career to the Next Level

Our application tracking tool helps you manage your job search effectively. Stay organized, track your progress, and land your dream tech job faster.

Your Product
Product promotion

Share this article

More Articles You Might Like

Latest Articles

Cover Image for How can I echo a newline in a batch file?
batch-filenewlinewindows

How can I echo a newline in a batch file?

Published on March 20, 2060

🔥 💻 🆒 Title: "Getting a Fresh Start: How to Echo a Newline in a Batch File" Introduction: Hey there, tech enthusiasts! Have you ever found yourself in a sticky situation with your batch file output? We've got your back! In this exciting blog post, we

Cover Image for How do I run Redis on Windows?
rediswindows

How do I run Redis on Windows?

Published on March 19, 2060

# Running Redis on Windows: Easy Solutions for Redis Enthusiasts! 🚀 Redis is a powerful and popular in-memory data structure store that offers blazing-fast performance and versatility. However, if you're a Windows user, you might have stumbled upon the c

Cover Image for Best way to strip punctuation from a string
punctuationpythonstring

Best way to strip punctuation from a string

Published on November 1, 2057

# The Art of Stripping Punctuation: Simplifying Your Strings 💥✂️ Are you tired of dealing with pesky punctuation marks that cause chaos in your strings? Have no fear, for we have a solution that will strip those buggers away and leave your texts clean an

Cover Image for Purge or recreate a Ruby on Rails database
rakeruby-on-railsruby-on-rails-3

Purge or recreate a Ruby on Rails database

Published on November 27, 2032

# Purge or Recreate a Ruby on Rails Database: A Simple Guide 🚀 So, you have a Ruby on Rails database that's full of data, and you're now considering deleting everything and starting from scratch. Should you purge the database or recreate it? 🤔 Well, my