2

I'm getting that error that says I have too many method references:

Error:The number of method references in a .dex file cannot exceed 64K.

It all started when I tried to change my targetSdkVersion to 24 and minSdkVersion to a lower sdk (19) via the gradle app file. That led me to having to change some values throughout the file like

 compile 'com.android.support:appcompat-v7:23.0.0'

to

 compile 'com.android.support:appcompat-v7:24.1.1'

I've read that people get this error when they have the wrong values in build.gradle. Here was my original build.gradle before the changes:

apply plugin: 'com.android.application'

android {
compileSdkVersion 23
buildToolsVersion "23.0.3"

defaultConfig {
    applicationId "com.delbridge.seth.alarm"
    minSdkVersion 23
    targetSdkVersion 23
    versionCode 1
    versionName "1.0"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'),        
    'proguard-rules.pro'
    }
    debug {
        debuggable true
    }
}
}

Any thoughts as to what's causing this?

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'

compile 'com.android.support:appcompat-v7:23.0.0'
compile 'com.mcxiaoke.volley:library-aar:1.0.0'
compile 'org.jsoup:jsoup:1.9.2'
compile 'org.jdeferred:jdeferred-android-aar:1.2.4'
compile 'com.google.android.gms:play-services-appindexing:9.0.2'
compile 'com.google.android.gms:play-services:9.0.2'
compile 'com.android.support:support-v4:23.0.0'
compile 'com.android.support:design:23.0.0'
compile 'com.android.support:cardview-v7:23.0.+'
compile 'com.android.support:recyclerview-v7:23.0.+'
compile 'com.google.firebase:firebase-ads:9.0.2'

}

apply plugin: 'com.google.gms.google-services'

And here is my build.gradle currently:

apply plugin: 'com.android.application'

android {
compileSdkVersion 24
buildToolsVersion "23.0.3"

defaultConfig {
    applicationId "com.delbridge.seth.alarm"
    minSdkVersion 19
    targetSdkVersion 24
    versionCode 1
    versionName "1.0"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
    debug {
        debuggable true
    }
}
}



dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:24.1.1'

compile 'com.mcxiaoke.volley:library-aar:1.0.0'
compile 'org.jsoup:jsoup:1.9.2'
compile 'org.jdeferred:jdeferred-android-aar:1.2.4'
compile 'com.google.android.gms:play-services-appindexing:9.4.0'
compile 'com.google.android.gms:play-services:9.4.0'

compile 'com.google.firebase:firebase-ads:9.4.0'
compile 'com.google.android.gms:play-services-ads:9.4.0'
compile 'com.google.android.gms:play-services-auth:9.4.0'
compile 'com.google.android.gms:play-services-gcm:9.4.0'

compile 'com.android.support:support-v4:24.1.1'
compile 'com.android.support:design:24.1.1'
compile 'com.android.support:cardview-v7:24.1.1'
compile 'com.android.support:recyclerview-v7:24.1.1'


}

apply plugin: 'com.google.gms.google-services'
sadelbrid
  • 411
  • 1
  • 4
  • 16

2 Answers2

4

You're unnecessarily including all of Google Play Services with this line:

compile 'com.google.android.gms:play-services:9.4.0'

So, remove that line and leave the ones that include the individual components:

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:24.1.1'

    compile 'com.mcxiaoke.volley:library-aar:1.0.0'
    compile 'org.jsoup:jsoup:1.9.2'
    compile 'org.jdeferred:jdeferred-android-aar:1.2.4'
    compile 'com.google.android.gms:play-services-appindexing:9.4.0'

    //remove this line:
    //compile 'com.google.android.gms:play-services:9.4.0'

    compile 'com.google.firebase:firebase-ads:9.4.0'
    compile 'com.google.android.gms:play-services-ads:9.4.0'
    compile 'com.google.android.gms:play-services-auth:9.4.0'
    compile 'com.google.android.gms:play-services-gcm:9.4.0'

    compile 'com.android.support:support-v4:24.1.1'
    compile 'com.android.support:design:24.1.1'
    compile 'com.android.support:cardview-v7:24.1.1'
    compile 'com.android.support:recyclerview-v7:24.1.1'
}

Note:

If the above solution does not solve your issue, then you will need to enable multidex.

Graham
  • 7,431
  • 18
  • 59
  • 84
Daniel Nugent
  • 43,104
  • 15
  • 109
  • 137
0

try this in your build.gradle file:

        android {
      compileSdkVersion 22
       buildToolsVersion "23.0.0"
        defaultConfig {
         minSdkVersion 14 //lower than 14 doesn't support multidex
         targetSdkVersion 22

         // Enabling multidex support.
         multiDexEnabled true
     }
 }

 dependencies {
 compile 'com.android.support:multidex:1.0.1'
 }

check this page: https://developers.google.com/android/guides/setup and use needed google play service

Damini Mehra
  • 3,257
  • 3
  • 13
  • 24