After update of AS to 1.0, getting “method ID not in [0, 0xffff]: 65536” error in project

后端 未结 2 401
余生分开走
余生分开走 2020-11-30 03:13

I updated Android Studio to the latest version, and let it \"fix the project\" and the like - but now my project does not compile, gives me

 FAILED

FAILURE         


        
相关标签:
2条回答
  • 2020-11-30 03:46

    The error means you have reached maximum method count in your app. That does include any libraries that you use for your project.

    There are two ways to tackle the issue:

    1. Get rid of any third-party libraries that you don't really need. If you use google play services that might contribute a lot to the method count. Fortunately as of the latest play-services release it is possible to include only parts of the framework.
    2. Use a multi dex setup for your application.
    0 讨论(0)
  • 2020-11-30 03:49

    I am phasing these problem & in my case used these link to overcome that error successfully..!!!

    The DEX 64k limit is not a problem anymore, almost

    To sum it up, adding multidex support:

    In case of

    UNEXPECTED TOP-LEVEL EXCEPTION:
    
    com.android.dex.DexIndexOverflowException: method ID not in [0, 0xffff]: 65536 
       at com.android.dx.merge.DexMerger$6.updateIndex(DexMerger.java:502) 
       at com.android.dx.merge.DexMerger$IdMerger.mergeSorted(DexMerger.java:277) 
       at com.android.dx.merge.DexMerger.mergeMethodIds(DexMerger.java:491) 
       at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:168) 
       at com.android.dx.merge.DexMerger.merge(DexMerger.java:189) 
       at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:454) 
       at com.android.dx.command.dexer.Main.runMonoDex(Main.java:302) 
       at com.android.dx.command.dexer.Main.run(Main.java:245) 
       at com.android.dx.command.dexer.Main.main(Main.java:214) 
       at com.android.dx.command.Main.main(Main.java:106)
    

    Google decided to release an official solution for this in the form of the MultiDex Support Library.

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

    Then enable multi-dexing by setting the multiDexEnabled flag in the buildType or productFlavor section of your gradle configuration.

    defaultConfig { 
       ... 
    multiDexEnabled true 
    ... 
    }
    

    Then depending on your project, you have 3 options:

    If you haven’t created your own Application class, simply declare android.support.multidex.MultiDexApplication as your application class in AndroidManifest.xml

       .... 
       android:name="android.support.multidex.MultiDexApplication" 
       ... 
    

    If you already have your own Application class, make it extend android.support.multidex.MultiDexApplication instead of android.app.Application

    If your Application class is extending some other class and you don’t want to or can’t change it, override attachBaseContext() as shown below:

    public class MyApplication extends FooApplication { 
       @Override 
       protected void attachBaseContext(Context base) { 
          super.attachBaseContext(base); 
          MultiDex.install(this); 
       } 
    }
    

    Your compilation process might run out of memory. To fix it, set the following dex options in the ‘android’ closure –

    dexOptions { 
       incremental true 
       javaMaxHeapSize "4g" 
    }
    

    More to know about multidex is here: http://developer.android.com/tools/building/multidex.html

    Another link which becomes helping to solve a these error : Referance Link

    0 讨论(0)
提交回复
热议问题