【问题标题】:Java Mail API error; duplicate entry: javax/mail/MultipartDataSource.classJava 邮件 API 错误;重复条目:javax/mail/MultipartDataSource.class
【发布时间】:2018-04-18 09:55:39
【问题描述】:

在生成签名的 APK 时,我收到了这个错误。我在项目中使用 Java 邮件 API 通过 Gmail 发送电子邮件。 在手机上运行它时没有错误,但是当尝试生成 apk 时会出现以下错误。谢谢。

Error:Execution failed for task ':app:transformClassesWithJarMergingForRelease'.> com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: javax/mail/MultipartDataSource.class

The error message

这是我的 gradle 依赖项;

    dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile files('./libs/ZSDK_ANDROID_API.jar')
    compile 'com.google.android.gms:play-services:8.4.0'
    compile 'com.google.code.ksoap2-android:ksoap2-android-assembly:3.6.1'
    compile 'com.android.support:multidex:1.0.1'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'

    testCompile 'junit:junit:4.12'
    compile files('libs/activation.jar')
    compile files('libs/javax.mail.jar')


}

这是我的 Mail.class

public boolean send() throws Exception {
    Properties props = _setProperties();

    if (!user.equals("") && !pass.equals("") && !to.equals("")
            && !from.equals("") && !subject.equals("")
            && !body.equals("")) {
        Session session = Session.getInstance(props, this);

        MimeMessage msg = new MimeMessage(session);

        msg.setFrom(new InternetAddress(from)); 
        msg.setRecipients(MimeMessage.RecipientType.TO,to);

        msg.setSubject(subject);
        msg.setSentDate(new Date());

        // setup message body
        MimeBodyPart messageBodyPart = new MimeBodyPart();
        messageBodyPart.setText(body.toString());
        multipart.addBodyPart(messageBodyPart);

        msg.setHeader("X-Priority", "1");
        msg.setContent(multipart);

        Transport.send(msg);

        return true;
    } else {
        return false;
    }
}

【问题讨论】:

  • 你有多少个 libs 文件夹? ./libslibs
  • 5 个库,还有未使用的库。 @IntelliJAmiya
  • 你应该从本地库部分清除。
  • 太棒了,它有效。非常感谢:) @IntelliJAmiya

标签: java android email jakarta-mail gmail-api


【解决方案1】:

问题,lib 文件夹中有一些未使用的库。正如@IntelliJAmiya 的建议,删除它们并解决问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-09-22
    • 1970-01-01
    • 1970-01-01
    • 2023-01-13
    • 1970-01-01
    • 2015-05-03
    • 2013-04-13
    相关资源
    最近更新 更多