Error while creating android app: java.util.zip.ZipException: duplicate entry: com / sun / mail / handlers / message_rfc822.class

I am developing an Android application that interacts with Picasa Web Albums. So I tried to upload a photo using the following code.

   protected Integer doInBackground(String... params) {

        int index = 0;
        int count = 0;
        URL albumPostUrl = null;
        try {
            albumPostUrl = new URL("https://picasaweb.google.com/data/feed/api/user/"+googuserName+"/albumid/" + params[1]);
        }
        catch (Exception ex)
        {
            ex.printStackTrace();
        }
        while(index < totalFBPicsCount)
        {
            PhotoEntry myPhoto = new PhotoEntry();
            myPhoto.setTitle(new PlainTextConstruct(params[2] + "_" + index));
            myPhoto.setClient("Photo Sync");
            MediaFileSource myMedia = new MediaFileSource(new File(params[0] + "/" + params[2] + "_" +index + ".jpg"), "image/jpeg");
            myPhoto.setMediaSource(myMedia);
            try
            {
            PhotoEntry returPic = myService.insert(albumPostUrl, myPhoto);
            }
            catch (RuntimeException ex)
            {
                ex.printStackTrace();
            }
            catch (Exception ex)
            {
                ex.printStackTrace();
                Log.e("Sai", "PhotSync", ex);
            }
            index++;
        }


        return null;

    }

      

myService.insert(albumPostUrl, myPhoto)

I got the following exception while executing the line . The logcat trace is shown below:

 06-05 01:18:04.086    4272-4422/krishtech.photosync E/dalvikvm﹕ 

    Could not find class 'com.google.gdata.data.media.MediaBodyPart$MediaSourceDataHandler', 
referenced from method com.google.gdata.data.media.MediaBodyPart.initMediaDataHandler 
06-05 01:18:04.091    4272-4422/krishtech.photosync E/dalvikvm﹕ Could not find class 'javax.activation.DataHandler', referenced from method com.google.gdata.data.media.MediaBodyPart.initMediaDataHandler 
06-05 01:18:04.101    4272-4422/krishtech.photosync E/dalvikvm﹕ Could not find class 'javax.mail.internet.CachedDataHandler', referenced from method javax.mail.internet.MimeBodyPart.createCachedDataHandler 
06-05 01:18:04.116    4272-4422/krishtech.photosync E/dalvikvm﹕ Could not find class 'javax.activation.DataHandler', referenced from method javax.mail.internet.MimeBodyPart.attachFile 
06-05 01:18:04.131    4272-4422/krishtech.photosync E/dalvikvm﹕ Could not find class 'javax.activation.DataHandler', referenced from method javax.mail.internet.MimeBodyPart.getDataHandler 
06-05 01:18:04.146    4272-4422/krishtech.photosync E/dalvikvm﹕ Could not find class 'javax.activation.DataHandler', referenced from method javax.mail.internet.MimeBodyPart.setContent 
06-05 01:18:04.146    4272-4422/krishtech.photosync E/dalvikvm﹕ Could not find class 'javax.activation.DataHandler', referenced from method javax.mail.internet.MimeBodyPart.setContent 06-05 01:18:08.866    4272-4422/krishtech.photosync E/AndroidRuntimeFATAL EXCEPTION: AsyncTask #3
            Process: krishtech.photosync, PID: 4272
            java.lang.RuntimeException: An error occured while executing doInBackground()
                    at android.os.AsyncTask$3.done(AsyncTask.java:300)
                    at java.util.concurrent.FutureTask.finishCompletion(FutureTask.java:355)
                    at java.util.concurrent.FutureTask.setException(FutureTask.java:222)
                    at java.util.concurrent.FutureTask.run(FutureTask.java:242)
                    at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
                    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
                    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
                    at java.lang.Thread.run(Thread.java:841)
             Caused by: java.lang.NoClassDefFoundError: javax.activation.DataHandler
                    at javax.mail.internet.MimeBodyPart.setContent(MimeBodyPart.java:678)
                    at com.google.gdata.data.media.MediaBodyPart.<init>(MediaBodyPart.java:95)
                    at com.google.gdata.data.media.MediaMultipart.<init>(MediaMultipart.java:126)
                    at com.google.gdata.client.media.MediaService.insert(MediaService.java:390)
                    at krishtech.photosync.MainActivity$startBackuptoGoogle.doInBackground(MainActivity.java:702)
                    at krishtech.photosync.MainActivity$startBackuptoGoogle.doInBackground(MainActivity.java:671)
                    at android.os.AsyncTask$2.call(AsyncTask.java:288)
                    at java.util.concurrent.FutureTask.run(FutureTask.java:237)
                    at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:231)
                    at  java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
                    at     java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
                    at java.lang.Thread.run(Thread.java:841)

      

After a bit of searching, it turned out that I have to use the android port for Java Mail from here . But when I added mail.jar

, activation.jar

and additional.jar

and tried to build the app, I get the following error in the Gradle console.

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:packageAllDebugClassesForMultiDex'.
> java.util.zip.ZipException: duplicate entry: com/sun/mail/handlers/message_rfc822.class

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED 

      

Then I see there are activ-1.1 and mail-1.4 libraries in External Libraries in addition to the libraries in the libs folder (mail.jar, activation.jar, Additional .jar). External libraries (mail-1.4 and activation-1.1) are automatically included as they are required dependencies for the Google Data Java Client Library that I use to get data from picasa. Below build.gradle

:

apply plugin: 'com.android.application'
android {
    compileSdkVersion 22
    buildToolsVersion "22.0.1"

    defaultConfig {
        applicationId "krishtech.photosync"
        minSdkVersion 15
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"
        multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    packagingOptions {
        exclude 'META-INF/LICENSE.txt'
    }

}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:22.1.1'
    compile 'com.facebook.android:facebook-android-sdk:4.1.0'
    compile 'com.google.android.gms:play-services-identity:7.5.0'
    compile('com.google.gdata:core:1.47.1') 
    compile('com.google.api-client:google-api-client:1.16.0-rc') {
        exclude(group: 'xpp3', module: 'xpp3') 
        exclude(group: 'org.apache.httpcomponents', module: 'httpclient') 
        exclude(group: 'junit', module: 'junit') 
        exclude(group: 'com.google.android', module: 'android') 
    }
    compile('com.google.api-client:google-api-client-android:1.16.0-rc') {
        exclude(group: 'com.google.android.google-play-services', module: 'google-play-services')
    }
    compile files('libs/activation.jar')
    compile files('libs/additionnal.jar')
    compile files('libs/mail.jar')
}

      

So now I'm fixing myself. If I need to delete mail-1.4 in the External Libraries folder (which I cannot do, please let me know how to do it) then I can cause an error in the gdata library and if I do not enable the java mail port .jar Maybe I can not upload photos. Please suggest how to fix this problem.

+3


source to share


1 answer


Well I solved this problem. The trick was to exclude mail-1.4.jar

that comes with com.google.gdata:core:1.47.1

to be included when you create the app. Made the following changes to build.gradle and now my app is working and also I can upload to Pics in Picasa using the android port for the Java mail library.



compile('com.google.gdata:core:1.47.1') {
    exclude(group: 'javax.mail', module: 'mail')
}

      

0


source







All Articles