gpt4 book ai didi

java - Android:NoClassDefFoundError:java.nio.charset.StandardCharsets 在 SDK 18 上发送电子邮件

转载 作者:行者123 更新时间:2023-12-01 16:53:30 30 4
gpt4 key购买 nike

我的应用程序当前正在通过正常的 SMTP 访问发送电子邮件,并且在 SDK 19+ 设备中工作正常,但在我的 Asus Android 4.3 SDK 18 中出现问题,并出现标题中所述的错误。

奇怪的是我没有使用 StandardCharsets.UTF_8 而是使用文字“UTF-8”并且没有区别

我还不打算进入 Gmail API,因为我没有心情“战斗”实现 oAuth 身份验证,因此我正在尝试为我已有的内容找到一些简单的修复方法。

下面是我正在使用的代码,无论我是否使用“UTF-8”参数都没有区别。 Transport.Send 行中始终出现相同的错误。

有什么想法可以让它在 SDK 18 设备上工作吗?

public static String send(String jsonEmail)
{
String result = Enum.Result.OK;

AppSettings appSettings = AppSettings.getInstance();

JSONObject oJsonEmail = TMJson.str2JSON(jsonEmail);

try {
String subject = oJsonEmail.getString("subject");
String message = oJsonEmail.getString("message");
String sendTo = oJsonEmail.getString("send_to");
String smtpServer = oJsonEmail.getString("smtp_server");
String smtpPort = oJsonEmail.getString("smtp_port");
String smtpUseAuth = oJsonEmail.getString("smtp_useauth");
boolean centerBodyText = Boolean.parseBoolean(oJsonEmail.getString("center_text"));

final String smtpUser = oJsonEmail.getString("smtp_user");
final String smtpPass = oJsonEmail.getString("smtp_pass");

Properties props = new Properties();
props.put("mail.smtp.host", smtpServer);
props.put("mail.smtp.port", smtpPort);
props.put("mail.smtp.auth", smtpUseAuth);
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.from.alias", "My App Name");

Session session = Session.getInstance(props,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(smtpUser, smtpPass);
}
});

message = TMJson.decodeEmail(message);
message = format(message, centerBodyText);

Message oMessage = new MimeMessage(session);
oMessage.setFrom(new InternetAddress(appSettings.emailFrom),
session.getProperty("mail.from.alias"), "UTF-8"));
oMessage.setRecipients(Message.RecipientType.TO, InternetAddress.parse(sendTo));
oMessage.setSubject(subject);
oMessage.setContent(message, "text/html; charset=iso-8859-2");

Transport.send(oMessage);
}catch (MessagingException | UnsupportedEncodingException | JSONException e) {
result = Enum.Result.KO;
ExceptionHandler.logException(e);
}

return result;
}

完整的日志:

05-06 15:45:29.152 12519-12519/com.xxx.xxx W/IInputConnectionWrapper: beginBatchEdit on inactive InputConnection
05-06 15:45:29.152 12519-12519/com.xxx.xxx W/IInputConnectionWrapper: endBatchEdit on inactive InputConnection
05-06 15:45:34.282 12519-12519/com.xxx.xxx W/IInputConnectionWrapper: beginBatchEdit on inactive InputConnection
05-06 15:45:34.282 12519-12519/com.xxx.xxx W/IInputConnectionWrapper: endBatchEdit on inactive InputConnection
05-06 15:45:37.552 12519-12519/com.xxx.xxx W/IInputConnectionWrapper: beginBatchEdit on inactive InputConnection
05-06 15:45:37.552 12519-12519/com.xxx.xxx W/IInputConnectionWrapper: endBatchEdit on inactive InputConnection
05-06 15:45:40.542 12519-12519/com.xxx.xxx W/IInputConnectionWrapper: beginBatchEdit on inactive InputConnection
05-06 15:45:40.542 12519-12519/com.xxx.xxx W/IInputConnectionWrapper: endBatchEdit on inactive InputConnection
05-06 15:45:52.962 12519-12519/com.xxx.xxx W/dalvikvm: VFY: unable to resolve virtual method 1600: Landroid/net/ConnectivityManager;.getActiveNetwork ()Landroid/net/Network;
05-06 15:45:52.992 12519-12519/com.xxx.xxx W/dalvikvm: VFY: unable to resolve direct method 5083: Landroid/widget/FrameLayout;.<init> (Landroid/content/Context;Landroid/util/AttributeSet;II)V
05-06 15:46:21.152 12519-12898/com.xxx.xxx W/dalvikvm: method Lcom/sun/mail/imap/IMAPStore;.getSession incorrectly overrides package-private method with same name in Ljavax/mail/Service;
05-06 15:46:21.152 12519-12898/com.xxx.xxx W/dalvikvm: method Lcom/sun/mail/pop3/POP3Store;.getSession incorrectly overrides package-private method with same name in Ljavax/mail/Service;
05-06 15:46:21.152 12519-12898/com.xxx.xxx W/dalvikvm: VFY: unable to resolve static field 41924 (UTF_8) in Ljava/nio/charset/StandardCharsets;
05-06 15:46:21.162 12519-12898/com.xxx.xxx W/dalvikvm: VFY: unable to resolve static field 41924 (UTF_8) in Ljava/nio/charset/StandardCharsets;
05-06 15:46:21.182 12519-12898/com.xxx.xxx W/dalvikvm: VFY: unable to resolve static field 41924 (UTF_8) in Ljava/nio/charset/StandardCharsets;
05-06 15:46:21.182 12519-12898/com.xxx.xxx W/dalvikvm: VFY: unable to resolve static field 41922 (ISO_8859_1) in Ljava/nio/charset/StandardCharsets;
05-06 15:46:21.212 12519-12898/com.xxx.xxx W/dalvikvm: VFY: unable to resolve virtual method 56512: Ljavax/activation/ActivationDataFlavor;.equals (Ljava/awt/datatransfer/DataFlavor;)Z
05-06 15:46:21.212 12519-12898/com.xxx.xxx W/dalvikvm: VFY: unable to find class referenced in signature ([Ljava/awt/datatransfer/DataFlavor;)
05-06 15:46:21.232 12519-12898/com.xxx.xxx W/dalvikvm: VFY: unable to resolve static field 41924 (UTF_8) in Ljava/nio/charset/StandardCharsets;
05-06 15:46:21.232 12519-12898/com.xxx.xxx W/dalvikvm: VFY: unable to resolve static field 41924 (UTF_8) in Ljava/nio/charset/StandardCharsets;
05-06 15:46:21.242 12519-12898/com.xxx.xxx W/dalvikvm: VFY: unable to resolve static field 41924 (UTF_8) in Ljava/nio/charset/StandardCharsets;
05-06 15:46:21.242 12519-12898/com.xxx.xxx W/dalvikvm: VFY: unable to resolve static field 41924 (UTF_8) in Ljava/nio/charset/StandardCharsets;
05-06 15:46:21.242 12519-12898/com.xxx.xxx W/dalvikvm: VFY: unable to resolve static field 41924 (UTF_8) in Ljava/nio/charset/StandardCharsets;
05-06 15:46:21.242 12519-12898/com.xxx.xxx W/dalvikvm: VFY: unable to resolve static field 41924 (UTF_8) in Ljava/nio/charset/StandardCharsets;
05-06 15:46:21.312 12519-12898/com.xxx.xxx W/dalvikvm: VFY: unable to resolve static field 41924 (UTF_8) in Ljava/nio/charset/StandardCharsets;
05-06 15:46:23.252 12519-12898/com.xxx.xxx W/dalvikvm: threadid=24: thread exiting with uncaught exception (group=0x42f05500)
05-06 15:46:23.252 12519-12898/com.xxx.xxx E/AndroidRuntime: FATAL EXCEPTION: pool-7-thread-1
java.lang.NoClassDefFoundError: java.nio.charset.StandardCharsets
at com.sun.mail.smtp.SMTPTransport$LoginAuthenticator.doAuth(SMTPTransport.java:979)
at com.sun.mail.smtp.SMTPTransport$Authenticator.authenticate(SMTPTransport.java:924)
at com.sun.mail.smtp.SMTPTransport.authenticate(SMTPTransport.java:858)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:762)
at javax.mail.Service.connect(Service.java:364)
at javax.mail.Service.connect(Service.java:222)
at javax.mail.Service.connect(Service.java:171)
at javax.mail.Transport.send0(Transport.java:230)
at javax.mail.Transport.send(Transport.java:100)
at com.xxx.xxx.helpers.TMEmail.send(TMEmail.java:78)
at com.xxx.xxx.activities.authentication.SendEmailTask.call(LoginActivity.java:876)
at com.xxx.xxx.activities.authentication.SendEmailTask.call(LoginActivity.java:864)
at com.xxx.xxx.helpers.TaskRunner.lambda$executeAsync$1$TaskRunner(TaskRunner.java:23)
at com.xxx.xxx.helpers.-$$Lambda$TaskRunner$S0wtc4khwtgNrHwkXyPnQb3di8w.run(lambda)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1080)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:573)
at java.lang.Thread.run(Thread.java:841)

Gradle :

api 'com.sun.mail:android-mail:1.6.4'
api 'com.sun.mail:android-activation:1.6.4'

最佳答案

好吧,是时候回答我自己的问题了(虽然很快,但我很焦躁,一直在研究)。

修复非常简单,只需将“com.sun.mail:android-mail”和“com.sun.mail:android-activation”降低到不使用“java.nio.charset.StandardCharsets”的最高版本即可”,即 1.5.5

api 'com.sun.mail:android-mail:1.5.5'
api 'com.sun.mail:android-activation:1.5.5'

也许这不是最好的解决方案,但它有效,所以我会将其标记为正确。

关于java - Android:NoClassDefFoundError:java.nio.charset.StandardCharsets 在 SDK 18 上发送电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61636567/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com