Announcement Announcement Module
Collapse
No announcement yet.
Importing Android Spring with Gradle Cause Error Mutiple Dex Files Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Importing Android Spring with Gradle Cause Error Mutiple Dex Files

    Hello guys! I have imported the android spring into my android project with the following:

    dependencies { compile 'org.springframework.android:spring-android-rest-template:1.0.1.RELEASE' compile 'org.springframework.android:spring-android-auth:1.0.1.RELEASE' compile 'org.springframework.android:spring-android-core:1.0.1.RELEASE' }
    and when I build my project, it show the error of "multiple dex file define Lorg.springframework.core.ErrorCoded", I have checked the library, and it seems like there are 2 ErrorCoded classes in the same package but in different lib. One is in "org.springframework.android:spring-android-core:1.0.1.RELEASE" and the other one is in "org.springframework:spring-core:3.0.7.RELEASE".

    Please let me know if there is anyone know how to solve this issue.

  • #2
    I'm running into the same issue. Any assistance would be greatly appreciated.

    Comment


    • #3
      I am also having this exact same error with both maven and gradle.

      Comment


      • #4
        @chandara can you share your build.gradle? You shouldn't have a dependency on org.springframework:spring-core:3.0.7.RELEASE, so that should be excluded. spring-android-core should have everything you need for Android compatibility.

        Comment


        • #5
          Originally posted by Roy Clarkson View Post
          @chandara can you share your build.gradle? You shouldn't have a dependency on org.springframework:spring-core:3.0.7.RELEASE, so that should be excluded. spring-android-core should have everything you need for Android compatibility.
          Code:
          compile 'org.springframework.android:spring-android-rest-template:1.0.1.RELEASE'
          compile 'org.springframework.android:spring-android-auth:1.0.1.RELEASE'
          compile 'org.springframework.android:spring-android-core:1.0.1.RELEASE'
          That's what mine looks like. Gradle automatically pulls down spring-core as soon as I try to build it.

          Comment


          • #6
            Hi,

            I had exactly the same problem with Android Studio (ver. 0.4.4) and Gradle. Reading this forum post and other sources, I researched how I could exclude the 'org.springframework:spring-core:3.0.7.RELEASE' module. In the end I modified the Gradle build file, so that it wouldn't include the 'spring-core' module, like this:
            Code:
            dependencies {
                compile 'com.android.support:support-v4:+'
                compile('org.springframework.android:spring-android-rest-template:1.0.1.RELEASE') {
                    exclude group :'org.springframework', module: 'spring-core'
                }
                compile('org.springframework.android:spring-android-auth:1.0.1.RELEASE') {
                    exclude group :'org.springframework', module: 'spring-core'
                }
                compile('org.springframework.android:spring-android-core:1.0.1.RELEASE') {
                    exclude group :'org.springframework', module: 'spring-core'
                }
            }
            Because I didn't know which of the org.spring.android modules depended on the spring-core, I added the exclude to all android modules. This resolved the "Multiple Dex Files error", but now I have new error:

            Code:
             : duplicate files during packaging of APK /Users/myusername/Development/Appname/Appname/Appname/build/apk/Appname-debug-unaligned.apk
              Execution failed for task ':Appname:packageDebug'.
            > Duplicate files copied in APK META-INF/notice.txt
                  File 1: /Users/myusername/.gradle/caches/modules-2/files-2.1/org.springframework.android/spring-android-auth/1.0.1.RELEASE/f43faebbf90aef324979a81a4f5eee1e3b95191f/spring-android-auth-1.0.1.RELEASE.jar
                  File 2: /Users/myusername/.gradle/caches/modules-2/files-2.1/org.springframework.android/spring-android-auth/1.0.1.RELEASE/f43faebbf90aef324979a81a4f5eee1e3b95191f/spring-android-auth-1.0.1.RELEASE.jar
            After another research I managed to get rid of the "duplicate files error" by modifying the build.gradle file, so that it excludes the conflicted META-INF files:

            Code:
            android {
                packagingOptions {
                    exclude 'META-INF/DEPENDENCIES.txt'
                    exclude 'META-INF/LICENSE.txt'
                    exclude 'META-INF/NOTICE.txt'
                    exclude 'META-INF/NOTICE'
                    exclude 'META-INF/LICENSE'
                    exclude 'META-INF/DEPENDENCIES'
                    exclude 'META-INF/notice.txt'
                    exclude 'META-INF/license.txt'
                    exclude 'META-INF/dependencies.txt'
                    exclude 'META-INF/LGPL2.1'
                }
            }
            I hope that these Gradle build file modifications help you as well, cause I lost at least half of the working day, just to find the solutions.
            Last edited by tarmopr; Feb 6th, 2014, 06:33 AM.

            Comment


            • #7
              The Spring for Android rest-template and core artifacts do not have a dependency on spring core or any Spring Framework library. However, the auth dependency does, along with Spring Social. You can exclude globally like the following, then you don't have to repeat the exclusion for each dependency. I also agree about the frustration with the packagingOptions in the newer Android Gradle plugin versions. It really should support a wildcard so you don't have to declare all those individually. Hopefully, Google will add that in the future.
              Code:
                configurations.compile {
                    exclude module: 'spring-core'
                    exclude module: 'spring-web'
                    exclude module: 'commons-logging'
                }
              There is also an example of this in the sample projects.

              Comment


              • #8
                Roy - this worked. Thank you VERY much. If you work for Spring, please put this in an FAQ or something to make it a bit more prominent.

                Cheers

                Comment


                • #9
                  Yeah, Roy's solution works for me too. Thanks.

                  Comment


                  • #10
                    I'm glad this worked for you. Thanks for the feedback! We'll include Gradle configuration information in the documentation for the next release. The sample applications already include Gradle and Maven configurations for each project.

                    Comment

                    Working...
                    X