Java Mail API错误;重复条目:javax / mail / MultipartDataSource.class

时间:2017-11-06 09:23:06

标签: java android email javamail gmail-api

在生成签名APK时,我收到此错误。我正在通过Gmail中的Java邮件API在项目中发送电子邮件。 在手机上运行时没有错误,但是当尝试生成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;
    }
}

1 个答案:

答案 0 :(得分:0)

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