You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

添加JavaMail API后Gradle构建报错:存在重复META-INF/LICENSE文件

Fixing "More than one file was found with OS independent path 'META-INF/LICENSE'" in Gradle (JavaMail API Case)

Hey there! I get it, dealing with Gradle errors when adding new libraries can be frustrating—especially when you're still getting the hang of how Gradle works. Let's break down this issue and fix it step by step.

What's causing this error?

When you added the JavaMail API, multiple dependencies in your project (likely JavaMail itself and other related libraries) are including identical META-INF/LICENSE files. Android's Gradle build system flags this as a conflict because it doesn't allow duplicate files in the final APK by default.

Solution 1: Exclude duplicate LICENSE files

The simplest fix is to tell Gradle to ignore all instances of the duplicate META-INF/LICENSE file. Here's how to do it:

  1. Open your app module's build.gradle file (not the root project's one—look for the file inside the app/ folder).
  2. Add the packagingOptions block inside the android section:
android {
    // Keep your existing configuration (compileSdk, defaultConfig, etc.) here

    packagingOptions {
        exclude 'META-INF/LICENSE'
        // If you also see errors about LICENSE.txt, add this line too:
        // exclude 'META-INF/LICENSE.txt'
    }
}
  1. Sync your Gradle project (click the "Sync Now" prompt that appears) and rebuild.

Solution 2: Pick the first occurrence instead of excluding

If you'd prefer to keep one copy of the LICENSE file instead of removing all, use pickFirst instead. This tells Gradle to use the first instance it finds and skip the rest:

android {
    // Existing configuration...

    packagingOptions {
        pickFirst 'META-INF/LICENSE'
    }
}

Why the previous ASL2.0 solution didn't work

The solution you tried was for META-INF/ASL2.0, which is a different license file. Since your error is about META-INF/LICENSE, you need to target that specific file path instead.

Give either of these methods a shot—they should resolve the conflict caused by the JavaMail API dependencies.

内容的提问来源于stack exchange,提问作者Paras Gupta

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 08:47:04