无法使用 Java 邮件的 App 引擎示例代码解析符号

Cannot resolve symbol using App engine's sample code for Java Mail

我已经按照 hello world 指南 here. The app can communicate with the backend server. My next step is code the backend such that it can send emails. I am following the official guide here 使用 Android Studio 在我的 Android 项目中成功设置了应用引擎后端。但是,我遇到了以下导入语句的问题,无法解决。

import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

我真的很纳闷为什么会像指南中特别说的那样"All of the JavaMail classes you need are included with the App Engine SDK. Do not add Oracle®'s JavaMail JARs to your app; if you do, the app will throw exceptions."

我在项目中包含了 App Engine SDK,否则 hello world 程序将无法运行。我不明白为什么导入语句没有解析。

这是我的 build.gradle 文件供参考。非常感谢您的帮助。

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.google.appengine:gradle-appengine-plugin:1.9.14'
    }
}
repositories {
    jcenter();
}
apply plugin: 'java'
apply plugin: 'war'
apply plugin: 'appengine'
sourceCompatibility = JavaVersion.VERSION_1_7
targetCompatibility = JavaVersion.VERSION_1_7
dependencies {
    appengineSdk 'com.google.appengine:appengine-java-sdk:1.9.14'
    compile 'javax.servlet:servlet-api:2.5'
}
appengine {
    downloadSdk = true
    appcfg {
        oauth2 = true
    }
}

好吧,我在几个小时后通过在 build.gradle 文件中添加 one 行来解决问题。

dependencies {
    appengineSdk 'com.google.appengine:appengine-java-sdk:1.9.18'
    compile 'com.google.appengine:appengine-api-1.0-sdk:1.9.18'
    compile 'javax.servlet:servlet-api:2.5'   
}

所以结果是

appengineSdk 'com.google.appengine:appengine-java-sdk:1.9.18'

不够。我的印象是这已经足够了,因为我可以 运行 hello world 程序就好了(即使用 GAE 的工具部署到后端工作,这意味着 sdk 依赖项已注册)。但是,当我尝试在 Java 代码中从 sdk 本身调用特定库时,它们无法解析。

解决方法是添加 编译依赖项。

compile 'com.google.appengine:appengine-api-1.0-sdk:1.9.18'

虽然我无法从官方文档中找到信息。事实上,如果不是 this article and the maven repo.

,我不知道如何正确地表达编译依赖性

希望这对在代码中使用 GAE 库的任何人有所帮助。