我已经在IntelliJ IDEA中创建了一个空的Android项目,并将以下行添加到app/build.gradle
:
dependencies {
...
compile 'javax.mail:javax.mail-api:1.6.2'
...
}
现在,我可以import javax.mail.internet.MimeBodyPart;
和javax.mail
的其他班级了:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
new MimeBodyPart();
}
应用程序成功构建。但是,如果我运行它,则会得到FATAL EXCEPTION
:
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/sun/mail/util/PropUtil;
at javax.mail.internet.MimeBodyPart.<clinit>(MimeBodyPart.java:91)
at com.example.myapplication.MainActivity.onCreate(MainActivity.java:15)
at android.app.Activity.performCreate(Activity.java:7136)
at android.app.Activity.performCreate(Activity.java:7127)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2893)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.sun.mail.util.PropUtil" on path: DexPathList[[zip file "/system/framework/org.apache.http.legacy.boot.jar", zip file "/data/app/com.example.myapplication-gtunpTdStbiuDO78f_fC_g==/base.apk", zip file "/data/app/com.example.myapplication-gtunpTdStbiuDO78f_fC_g==/split_lib_dependencies_apk.apk", zip file "/data/app/com.example.myapplication-gtunpTdStbiuDO78f_fC_g==/split_lib_slice_0_apk.apk", zip file "/data/app/com.example.myapplication-gtunpTdStbiuDO78f_fC_g==/split_lib_slice_1_apk.apk", zip file "/data/app/com.example.myapplication-gtunpTdStbiuDO78f_fC_g==/split_lib_slice_2_apk.apk", zip file "/data/app/com.example.myapplication-gtunpTdStbiuDO78f_fC_g==/split_lib_slice_3_apk.apk", zip file "/data/app/com.example.myapplication-gtunpTdStbiuDO78f_fC_g==/split_lib_slice_4_apk.apk", zip file "/data/app/com.example.myapplication-gtunpTdStbiuDO78f_fC_g==/split_lib_slice_5_apk.apk", zip file "/data/app/com.example.myapplication-gtunpTdStbiuDO78f_fC_g==/split_lib_slice_6_apk.apk", zip file "/data/app/com.example.myapplication-gtunpTdStbiuDO78f_fC_g==/split_lib_slice_7_apk.apk", zip file "/data/app/com.example.myapplication-gtunpTdStbiuDO78f_fC_g==/split_lib_slice_8_apk.apk", zip file "/data/app/com.example.myapplication-gtunpTdStbiuDO78f_fC_g==/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/com.example.myapplication-gtunpTdStbiuDO78f_fC_g==/lib/x86, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:134)
at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
at javax.mail.internet.MimeBodyPart.<clinit>(MimeBodyPart.java:91)
at com.example.myapplication.MainActivity.onCreate(MainActivity.java:15)
at android.app.Activity.performCreate(Activity.java:7136)
at android.app.Activity.performCreate(Activity.java:7127)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2893)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
答案 0 :(得分:0)
javax.mail:javax.mail-api:1.6.2
是Java SE的实现,而不是Android的实现。尝试使用另一个库:
compile 'com.sun.mail:android-mail:1.6.2'