尝试在Android应用中使用JavaMail连接到imap商店时出现以下错误:
IMAP DEBUG:无法加载SASL身份验证器:java.lang.NoSuchMethodException:[class com.sun.mail.imap.protocol.IMAPProtocol,class java.lang.String,class java.util.Properties,boolean,class java.io.PrintStream,类java.lang.String]
我遇到的问题与此处描述的问题相同: ProGuard java.lang.NoSuchMethodException
...但是将线添加到proguard的解决方案没有帮助。
public class OAuth2SaslClientFactory implements SaslClientFactory {
private static final Logger logger =
Logger.getLogger(OAuth2SaslClientFactory.class.getName());
public static final String OAUTH_TOKEN_PROP =
"mail.imaps.sasl.mechanisms.oauth2.oauthToken";
public SaslClient createSaslClient(String[] mechanisms,
String authorizationId,
String protocol,
String serverName,
Map<String, ?> props,
CallbackHandler callbackHandler) {
boolean matchedMechanism = false;
for (int i = 0; i < mechanisms.length; ++i) {
if ("XOAUTH2".equalsIgnoreCase(mechanisms[i])) {
matchedMechanism = true;
break;
}
}
if (!matchedMechanism) {
logger.info("Failed to match any mechanisms");
return null;
}
return new OAuth2SaslClient((String) props.get(OAUTH_TOKEN_PROP),
callbackHandler);
}
public String[] getMechanismNames(Map<String, ?> props) {
return new String[] {"XOAUTH2"};
}
}
public OAuth2Provider() {
super("Google OAuth2 Provider", 1.0,
"Provides the XOAUTH2 SASL Mechanism");
put("SaslClientFactory.XOAUTH2",
"com.app.OAuth2SaslClientFactory");
}
答案 0 :(得分:0)
我无法准确确定proguard中缺少的内容,但我确实通过在proguard文件中添加以下行来结束项目运行:
-dontshrink
答案 1 :(得分:-1)
您是否尝试使用JavaMail 1.5.2,其中包含built-in OAuth2 support,因此不需要上述任何代码?