Andrew Raleigh
Andrew Raleigh

Reputation: 321

Multiple dex files define in Android Studio

I know this is a common issue, but I've checked all other posts and none of them helped. A lot of them are for eclipse, and the ones for android studio don't help.

Error:Execution failed for task ':app:transformClassesWithDexForDebug'.
> com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.dex.DexException: Multiple dex files define Lcom/android/volley/VolleyError;

What I've tried:

First, I get the bug that it is a repository but there is no git, so I just remove volley (that worked for my teammate). Then, while all other 4 members get it to work, mine stalls and bugs there. There are also 4 warnings, one is below, the rest are similar:

Warning:warning: Ignoring InnerClasses attribute for an anonymous inner class
(org.apache.commons.logging.impl.WeakHashtable$1) that doesn't come with an
associated EnclosingMethod attribute. This class was probably produced by a
compiler that did not target the modern .class file format. The recommended
solution is to recompile the class from source, using an up-to-date compiler
and without specifying any "-target" type options. The consequence of ignoring
this warning is that reflective operations on this class will incorrectly
indicate that it is *not* an inner class.

If it helps, this is the gradle file below:

apply plugin: 'com.android.application'

dependencies {

    compile fileTree(include: ['*.jar'], dir: 'libs')
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile files('libs/commons-logging-1.2.jar')
    compile files('libs/com.fasterxml.jackson.databind.jar')
    compile files('libs/gson-2.3.1.jar')
    compile files('libs/httpclient-4.5.1.jar')
    compile files('libs/httpcore-4.4.3.jar')
    compile files('libs/jackson-core-2.7.1.jar')
    compile files('libs/sun.misc.BASE64Decoder.jar')
    compile files('libs/jackson-annotations-2.7.1.jar')
    compile files('libs/jackson-databind-2.7.1-1.jar')
    compile 'com.android.support:appcompat-v7:25.3.0'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    compile 'com.mcxiaoke.volley:library-aar:1.0.0'
    compile 'com.android.volley:volley:1.0.0'
    compile 'com.android.support:recyclerview-v7:25.3.0'
    compile 'com.android.support:gridlayout-v7:25.3.0'
    compile 'com.android.support:cardview-v7:25.3.0'
    compile 'com.android.support:design:25.3.0'
    compile 'com.android.volley:volley:1.0.0'
    testCompile 'junit:junit:4.12'
}

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.2"

    defaultConfig {
        applicationId "com.csc301.team7.era"
        minSdkVersion 15
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    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'
    }
}

Removing two of the extra volley lines in gradle in turn gives me this error in gradle:

Error:Execution failed for task ':app:transformClassesWithDexForDebug'.
> com.android.build.api.transform.TransformException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.dex.DexException: Multiple dex files define Lcom/fasterxml/jackson/databind/AbstractTypeResolver;

but I can't find AbstractTypeResolver.

Please, any help getting this project to run would be greatly appreciated.

Upvotes: 1

Views: 909

Answers (1)

Zoe - Save the data dump
Zoe - Save the data dump

Reputation: 28228

This error:

Ignoring InnerClasses attribute for an anonymous inner class

is an issue I had too. It is an issue related to inner classes when using Proguard. It can be solved by adding the following to your proguard file:

-keepattributes EnclosingMethod
-keepattributes InnerClasses

Proguard and inner classes often lead to issues. By adding the lines above, you indicate to Proguard that it should keep inner classes where they are and not treat them as if they are in their own files.

Upvotes: 1

Related Questions