18

I'm trying to import https://github.com/Kickflip/kickflip-android-sdk using gradle into my android build and I'm getting :

UNEXPECTED TOP-LEVEL EXCEPTION: com.android.dex.DexException: Multiple dex files define Lorg/apache/commons/codec/binary/Base64;

Commons.codec is a dependency of my project, but not directly of the kick-flip project, I think its coming from one of the jars included there. I can see the .class files if I open Kickflip's classes.jar.

How can I exclude Base64.class from being imported from kickflip into the final build? I've looked at using ziptree to exclude things but haven't been able to get anything to work.

Thanks

My build.gradle is:

apply plugin: 'android'

android {
    compileSdkVersion 19
    buildToolsVersion "19.0.3"

    defaultConfig {
        minSdkVersion 10
        targetSdkVersion 19
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            runProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }

    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'
        exclude 'META-INF/ASL2.0'
    }

    android.applicationVariants.all{ variant ->
        // This is an annoying hack to get around the fact that the Gradle plugin does not support
        // having libraries with different minSdkVersions. Play Services has a min version of 9 (Gingerbread)
        // but Android Maps Utils supports 8 (Froyo) still
        variant.processManifest.doFirst {
        File manifestFile = file("${buildDir}/exploded-aar/io.kickflip/sdk/0.9.9/AndroidManifest.xml")
            if (manifestFile.exists()) {
                println("Replacing minSdkVersion in Android Maps Utils")
                String content = manifestFile.getText('UTF-8')
                content = content.replaceAll(/minSdkVersion="18"/, 'minSdkVersion=\"10\"')
                manifestFile.write(content, 'UTF-8')
                println(content)
            }
        }
    }
}

dependencies {
    compile 'com.android.support:support-v4:19.1.0'
    compile 'io.kickflip:sdk:0.9.9'
    compile fileTree(dir: 'libs', include: '*.jar')
    compile project(':libs:typeface-textview:library')
    compile project(':libs:gpuimage')
    compile 'com.google.android.gms:play-services:4.3.23'
    compile 'com.nineoldandroids:library:2.4.0'
    compile 'com.koushikdutta.urlimageviewhelper:urlimageviewhelper:1.0.4'
    compile ('fr.avianey:facebook-android-api:3.14.0') {
      exclude module: 'support-v4'
    }
    compile 'com.github.japgolly.android:svg-android:2.0.1'
    compile 'org.scribe:scribe:1.3.5'
    compile 'commons-codec:commons-codec:1.8'
}
Cœur
  • 37,241
  • 25
  • 195
  • 267
silverscania
  • 647
  • 1
  • 6
  • 16
  • I see that the kickflip requires minimum android sdk version 18. And your build file defines minSdkVersion 10. This might be a problem. – Genry Feb 05 '15 at 20:02
  • I tried to build it as well. They seem to be saying that build tools 19.1 have to be used and are saying to build from a Gradle command line. I'm on Android Studio so the examples just complain about the gradle version being to old to be supported. The easy download button for Eclipse is gone from developer.android.com. – Eae Mar 30 '15 at 23:42
  • I've gotten multiple dex errors before in Eclipse it usually has to do with incorrect library linkage or perhaps a library being included multiple times. This is perhaps why they are suggesting the use of a Gradle command line build. – Eae Mar 31 '15 at 03:22
  • possible duplicate of [Unable to execute dex: Multiple dex files define Lcom/myapp/R$array;](http://stackoverflow.com/questions/7870265/unable-to-execute-dex-multiple-dex-files-define-lcom-myapp-rarray) – Jared Burrows Apr 04 '15 at 02:12
  • Please, mark the answer as accepted If helped you. Thanks – webo80 Dec 15 '15 at 08:25
  • Sorry, its a year too late dude, I have no way of verifying this anymore – silverscania Dec 16 '15 at 07:30

1 Answers1

-2

Probably the problem is Base64 class included twice. It is in the 'google-http-client' (view it). Try to exclude this class. If you're lucky, being an Util class, it isn't used in the code.

Try this in your build.gradle:

package com.google.api.client.util;

 sourceSets {
     main {
         java {
             exclude 'com.google.api.client.util.Base64.java'
             exclude 'org.apache.commons.codec.binary.Base64.java'
         }
     }
}

NOTE: I don't tried it yet, but sounds as a possibility

webo80
  • 3,365
  • 5
  • 35
  • 52