本文介绍了java.lang.NoClassDefFound错误的javax API的Gmail的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了Gmail客户端我工作的一个例外。唯一的例外是

I'm running into an exception in a gmail client I'm working on. The exception is the

java.lang.NoClassDefFound 所触发的getDefaultInstance行

java.lang.NoClassDefFound that is triggered on the getDefaultInstance line

   Properties props = new Properties();
        Session session = Session.getDefaultInstance(props, null);

我已经包括使用javax罐子如下:

I've included the javax jar as follows:

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:22.2.0'
    compile 'com.google.android.gms:play-services:7.3.0'
    compile 'com.google.api-client:google-api-client:1.20.0'
    compile 'com.google.api-client:google-api-client-android:1.20.0'
    compile 'com.google.api-client:google-api-client-gson:1.20.0'
    compile 'com.google.apis:google-api-services-gmail:v1-rev29-1.20.0'
    compile  'javax.mail:javax.mail-api:1.5.2'
}

我GOOGLE了这一点,但不太清楚如何来解决这个问题。我试过干净重建,并在这两种情况下的异常抛出依然。任何帮助将是AP preciated。

I've googled this but not quite sure how to fix this. I've tried clean and rebuild and in both cases the exception is still thrown. Any help would be appreciated.

Exeception详细消息:

Exeception detail Message:

Didn't find class "com.sun.mail.util.MailLogger" on path: DexPathList[[zip file "/data/app/com.android.application.androidgmailclient-2/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]

更新

我发现缺少类MailLogger不是javax.mail-API的一部分,而这是一部分javax.mail:邮箱:1.5.0-B01罐子1.5.0-B01作为最新版本:

I found that the missing class "MailLogger" is not a part of the javax.mail-api rather it is a part of the 'javax.mail:mail:1.5.0-b01' jar with 1.5.0-b01 being the latest version:

所以,我包括编译javax.mail:邮箱:1.5.0-B01进入我的gradle这个文件,然后我找到了外部库的罐子。我复制的jar到应用程序/库,然后点击添加为库。我可以看到MailLogger类现在是present这是什么在异常轰炸。我的文件的gradle现在看起来是这样的:

So I included the compile 'javax.mail:mail:1.5.0-b01' into my gradle file and then I found the jar in the external libraries. I copied the jar into app/libs and then hit "Add as Library". I can see that the MailLogger class is now present which is what was bombing in the exception. My gradle file now looks like this:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 22
    buildToolsVersion "23.0.0 rc2"

    packagingOptions{
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
    }

    defaultConfig {
        applicationId "com.android.app.androidgmailclient"
        minSdkVersion 16
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}


dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:22.2.0'
    compile 'com.google.android.gms:play-services:7.3.0'
    compile 'com.google.api-client:google-api-client:1.20.0'
    compile 'com.google.api-client:google-api-client-android:1.20.0'
    compile 'com.google.api-client:google-api-client-gson:1.20.0'
    compile 'com.google.apis:google-api-services-gmail:v1-rev29-1.20.0'
    compile 'javax.mail:mail:1.5.0-b01'
    compile files('libs/mail-1.5.0-b01.jar')
}

然而,当我现在就去建项目中,我得到这个生成错误:

However, when I go to build the project now I get this build error:

错误:执行失败的任务:应用程序:dexDebug

Error:Execution failed for task ':app:dexDebug'.

com.android.ide.common.process.ProcessException:org.gradle.process.internal.ExecException:过程'命令'/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/bin/ Java的非零退出值完成2

任何想法?

推荐答案

因为你加两次相同的库发生这种错误。

This error occurred because you are adding same library twice.

compile 'javax.mail:mail:1.5.0-b01'
compile files('libs/mail-1.5.0-b01.jar')

删除这些行,然后我觉得应该很好地工作之一。

delete one of these line then I think it should work fine.

这篇关于java.lang.NoClassDefFound错误的javax API的Gmail的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-29 17:07