Resolving the “More than one file was found with OS independent path ‘META-INF/LICENSE'” Error in Android Studio

Resolving the "More than one file was found with OS independent path 'META-INF/LICENSE'" Error in Android Studio

6 June 2024 Stephan Petzl Leave a comment Tech-Help

When building your Android application, you might encounter the following error:

Error: Execution failed for task ':app:transformResourcesWithMergeJavaResForDebug'.
More than one file was found with OS independent path 'META-INF/LICENSE'

This error typically occurs when there are duplicate files in your project’s dependencies. This guide will help you resolve this issue efficiently.

Understanding the Issue

When Gradle builds your APK, it consolidates content from all dependencies. If multiple dependencies contain the same file, Gradle will flag this as a conflict. Common files that cause this issue include:

  • META-INF/LICENSE
  • META-INF/NOTICE
  • META-INF/DEPENDENCIES

Solution

To resolve this issue, you can exclude these files from the packaging process in your build.gradle file. Here’s a step-by-step guide:

Step 1: Modify Your build.gradle File

Add the following code snippet inside the android block of your build.gradle file:

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

This code excludes the conflicting files from the final APK package.

Step 2: Clean and Rebuild Your Project

After updating your build.gradle file, clean and rebuild your project to apply the changes:

  • Go to Build > Clean Project.
  • Then, go to Build > Rebuild Project.

Alternative Solution for Gradle 7.0.2 and Later

If you are using Gradle 7.0.2 or later, the exclude function is deprecated. Use the following code instead:

android {
    packagingOptions {
        resources.excludes.add("META-INF/*")
    }
}

Additional Considerations

In some cases, the error might be caused by specific .so files or other resource files. You can use the pickFirst option to resolve such conflicts:

android {
    packagingOptions {
        pickFirst 'lib/armeabi-v7a/libassmidi.so'
        pickFirst 'lib/x86/libassmidi.so'
    }
}

Conclusion

By following these steps, you should be able to resolve the “More than one file was found with OS independent path ‘META-INF/LICENSE'” error and successfully build your Android application. For more advanced configurations and troubleshooting, refer to our Advanced Configuration guide.

Streamlining Your Testing Process with Repeato

While resolving build issues is crucial, ensuring your app’s quality through consistent testing is equally important. Repeato is a powerful no-code test automation tool for iOS and Android that simplifies the creation, execution, and maintenance of automated tests. By leveraging computer vision and AI, Repeato allows both developers and non-technical team members to focus on delivering a robust application without the overhead of manual testing.

To learn more about how Repeato can enhance your development workflow, visit our documentation or contact us for a personalized demo.

Like this article? there’s more where that came from!