0

I took a new android project. It ran fine on device. Then I added -

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

Now when i try to run the app, it gives -

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

Any help?

s.k.paul
  • 7,099
  • 28
  • 93
  • 168
  • Possible duplicate of http://stackoverflow.com/questions/36785014/the-number-of-method-references-in-a-dex-file-cannot-exceed-64k-api-17 – Jay Rathod Sep 05 '16 at 08:39
  • There's so much info regarding 64k limit online, I can't believe you didn't find anything useful before posting to SO. – Egor Sep 05 '16 at 08:51
  • Read this, http://jakewharton.com/play-services-is-a-monolith/ and https://medium.com/@rotxed/dex-skys-the-limit-no-65k-methods-is-28e6cb40cf71#.rqu4x1qos – K Neeraj Lal Sep 05 '16 at 08:53
  • @Egor you are correct ..there's so much info regarding 64k limit online – Dileep Patel Sep 05 '16 at 10:11

3 Answers3

0

You have two ways to deal with this.

  1. Enable MultiDex :

    android {
        compileSdkVersion 22
        buildToolsVersion "23.0.0"
    
         defaultConfig {
             minSdkVersion 14 //lower than 14 doesn't support multidex
             targetSdkVersion 22
    
             // Enabling multidex support.
             multiDexEnabled true
         }
    }
    
  2. Use specific play services needed in your application instead of whole package as described here:

    Add dependency for specific Play service from this list

Dipali Shah
  • 3,742
  • 32
  • 47
0

That mean your method in your project exceed 65535. You can see this:

Configure Apps with Over 64K Methods

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

Will load all the methods and packages from the google play services. This is actually a wrong way to add a dependency. If you want to use a particular thing from google play services, then add only that particular package.

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

This will load only location package and hence it will decrease the method references.

Anju
  • 9,379
  • 14
  • 55
  • 94