1

I'm getting the following error when I try to run the Android app.

Error:Execution failed for task ':app:transformResourcesWithMergeJavaResForDebug'.
> com.android.build.api.transform.TransformException: com.android.builder.packaging.DuplicateFileException: Duplicate files copied in APK META-INF/INDEX.LIST
    File1: /Users/Antrromet/.gradle/caches/modules-2/files-2.1/org.apache.xmlbeans/xmlbeans/2.6.0/29e80d2dd51f9dcdef8f9ffaee0d4dc1c9bbfc87/xmlbeans-2.6.0.jar
    File2: /Users/Antrromet/.gradle/caches/modules-2/files-2.1/edu.ucar/cdm/4.5.5/af1748a3d024069cb7fd3fc2591efe806c914589/cdm-4.5.5.jar
    File3: /Users/Antrromet/.gradle/caches/modules-2/files-2.1/edu.ucar/httpservices/4.5.5/ee5f217be599e5e03f7f0e55e03f9e721a154f62/httpservices-4.5.5.jar
    File4: /Users/Antrromet/.gradle/caches/modules-2/files-2.1/edu.ucar/netcdf4/4.5.5/675d63ecc857c50dd50858011b670160aa30b62/netcdf4-4.5.5.jar
    File5: /Users/Antrromet/.gradle/caches/modules-2/files-2.1/edu.ucar/grib/4.5.5/cfe552910e9a8d57ce71134796abb281a74ead16/grib-4.5.5.jar
    File6: /Users/Antrromet/.gradle/caches/modules-2/files-2.1/edu.ucar/udunits/4.5.5/d8c8d65ade13666eedcf764889c69321c247f153/udunits-4.5.5.jar

I know there are similar questions here and here, and I've taken hints from both of them. This is how my gradle file looks like.

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    defaultConfig {
        applicationId "com.antrromet.androidtikaparser"
        minSdkVersion 15
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    packagingOptions {
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'

        exclude 'META-INF/maven/edu.ucar/udunits/pom.xml'
        exclude 'META-INF/maven/edu.ucar/udunits/pom.properties'

        exclude 'META-INF/maven/edu.ucar/netcdf4/pom.xml'
        exclude 'META-INF/maven/edu.ucar/netcdf4/pom.properties'

        exclude 'META-INF/maven/edu.ucar/cdm/pom.xml'
        exclude 'META-INF/maven/edu.ucar/cdm/pom.properties'

        exclude 'META-INF/maven/edu.ucar/grib/pom.xml'
        exclude 'META-INF/maven/edu.ucar/grib/pom.properties'

        exclude 'META-INF/maven/org.apache.xmlbeans/xmlbeans/pom.xml'
        exclude 'META-INF/maven/org.apache.xmlbeans/xmlbeans/pom.properties'

        exclude 'META-INF/maven/edu.ucar/httpservices/pom.xml'
        exclude 'META-INF/maven/edu.ucar/httpservices/pom.properties'
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.2.1'
    compile('org.apache.tika:tika-parsers:1.12') {
        exclude group: 'commons-logging', module: 'commons-logging'
        exclude group: 'org.json', module: 'json'
        exclude group: 'org.apache.httpcomponents', module: 'httpclient'
    }
}

Any suggestions as to how to solve this? Thanks in advance!

EDIT 1

When I add exclude 'META-INF/INDEX.LIST', the error changes to the following,

Error:Execution failed for task ':app:transformResourcesWithMergeJavaResForDebug'.
> com.android.build.api.transform.TransformException: com.android.builder.packaging.DuplicateFileException: Duplicate files copied in APK META-INF/services/org.apache.sis.storage.DataStoreProvider
    File1: /Users/Antrromet/.gradle/caches/modules-2/files-2.1/org.apache.sis.storage/sis-storage/0.5/29d1ea6422b68fbfe1f1702f122019ae376ee2c8/sis-storage-0.5.jar
    File2: /Users/Antrromet/.gradle/caches/modules-2/files-2.1/org.apache.sis.storage/sis-netcdf/0.5/2b416e4506caebe7df6dd21b878dae888e0eea39/sis-netcdf-0.5.jar

And after that if you add the following,

exclude 'META-INF/maven/org.apache.sis.storage/sis-netcdf/pom.xml'
exclude 'META-INF/maven/org.apache.sis.storage/sis-netcdf/pom.properties'

exclude 'META-INF/maven/org.apache.sis.storage/sis-storage/pom.xml'
exclude 'META-INF/maven/org.apache.sis.storage/sis-storage/pom.properties'

Its the exact same error as above. It doesn't change.

Community
  • 1
  • 1
Antrromet
  • 15,294
  • 10
  • 60
  • 75
  • Have you tried excluding `META-INF/INDEX.LIST`? – OneCricketeer Mar 30 '16 at 03:27
  • @cricket_007 I did try that already. Check my edited question. – Antrromet Mar 30 '16 at 03:34
  • Are all those errors just coming from Tika? – OneCricketeer Mar 30 '16 at 03:36
  • @cricket_007 Yes thats the only library I'm trying to use. What I'm guessing is, Tika internally is using those jars and hence there is a conflict. But am sure there must be a way to stop that in Android while packaging the apk. – Antrromet Mar 30 '16 at 03:38
  • First result for Tika Android gave me this http://stackoverflow.com/questions/8135775/is-tika-compatible-with-android – OneCricketeer Mar 30 '16 at 03:46
  • @cricket_007 Yes, I saw that too. But I just wanted to start afresh as that thread is very old (around 4 years old). Both Android and Tika have evolved quite a lot since then! – Antrromet Mar 30 '16 at 03:49
  • I'm sure it has. Personally, I've never used Tika, but I'm sure there are lots of unnecessary dependencies for Android usage – OneCricketeer Mar 30 '16 at 03:54
  • @cricket_007 Agreed. Tika as a whole is too heavy for mobile, but just out of curiosity I wanted to try the same. – Antrromet Mar 30 '16 at 03:56

1 Answers1

1

You need to add the following exclude:

exclude 'META-INF/services/org.apache.sis.storage.DataStoreProvider'
Michael
  • 53,859
  • 22
  • 133
  • 139
  • This did solve my particular issue, but then after I did this there were other things that I had to exclude and it just kept on going on and on! I've just left this at the moment, will check in detail at a better time. P.S. I'm sorry for such a delayed response. – Antrromet Apr 06 '16 at 16:45