Unable to execute dex: method ID not in [0, 0xffff]: 65536

前端 未结 12 2001
独厮守ぢ
独厮守ぢ 2020-11-21 18:48

I have seen various versions of the dex erros before, but this one is new. clean/restart etc won\'t help. Library projects seems intact and dependency seems to be linked cor

相关标签:
12条回答
  • 2020-11-21 19:18

    I've shared a sample project which solve this problem using custom_rules.xml build script and a few lines of code.

    I used it on my own project and it is runs flawless on 1M+ devices (from android-8 to the latest android-19). Hope it helps.

    https://github.com/mmin18/Dex65536

    0 讨论(0)
  • 2020-11-21 19:19

    gradle + proguard solution:

    afterEvaluate {
      tasks.each {
        if (it.name.startsWith('proguard')) {
            it.getInJarFilters().each { filter ->
                if (filter && filter['filter']) {
                    filter['filter'] = filter['filter'] +
                            ',!.readme' +
                            ',!META-INF/LICENSE' +
                            ',!META-INF/LICENSE.txt' +
                            ',!META-INF/NOTICE' +
                            ',!META-INF/NOTICE.txt' +
                            ',!com/google/android/gms/ads/**' +
                            ',!com/google/android/gms/cast/**' +
                            ',!com/google/android/gms/games/**' +
                            ',!com/google/android/gms/drive/**' +
                            ',!com/google/android/gms/wallet/**' +
                            ',!com/google/android/gms/wearable/**' +
                            ',!com/google/android/gms/plus/**' +
                            ',!com/google/android/gms/topmanager/**'
                }
            }
        }
      }
    }
    
    0 讨论(0)
  • 2020-11-21 19:20

    Remove some jar file from Libs folder and copy to some other folder, And Go to _Project Properties > Select Java Build Path, Select Libraries, Select Add External Jar, Select the Removed jar to your project, Click save, this will be added under Referenced Library instead of Libs folder. Now clean and Run your project. You dont need to add Any code for MultDex. Its simply worked for me.

    0 讨论(0)
  • 2020-11-21 19:23

    Update 3 (11/3/2014)
    Google finally released official description.


    Update 2 (10/31/2014)
    Gradle plugin v0.14.0 for Android adds support for multi-dex. To enable, you just have to declare it in build.gradle:

    android {
       defaultConfig {
          ...
          multiDexEnabled  true
       }
    }
    

    If your application supports Android prior to 5.0 (that is, if your minSdkVersion is 20 or below) you also have to dynamically patch the application ClassLoader, so it will be able to load classes from secondary dexes. Fortunately, there's a library that does that for you. Add it to your app's dependencies:

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

    You need to call the ClassLoader patch code as soon as possible. MultiDexApplication class's documentation suggests three ways to do that (pick one of them, one that's most convenient for you):

    1 - Declare MultiDexApplication class as the application in your AndroidManifest.xml:

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.example.android.multidex.myapplication">
        <application
            ...
            android:name="android.support.multidex.MultiDexApplication">
            ...
        </application>
    </manifest>
    

    2 - Have your Application class extend MultiDexApplication class:

    public class MyApplication extends MultiDexApplication { .. }
    

    3 - Call MultiDex#install from your Application#attachBaseContext method:

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

    Update 1 (10/17/2014):
    As anticipated, multidex support is shipped in revision 21 of Android Support Library. You can find the android-support-multidex.jar in /sdk/extras/android/support/multidex/library/libs folder.


    Multi-dex support solves this problem. dx 1.8 already allows generating several dex files.
    Android L will support multi-dex natively, and next revision of support library is going to cover older releases back to API 4.

    It was stated in this Android Developers Backstage podcast episode by Anwar Ghuloum. I've posted a transcript (and general multi-dex explanation) of the relevant part.

    0 讨论(0)
  • 2020-11-21 19:23

    Your project is too large. You have too many methods. There can only be 65536 methods per application. see here https://code.google.com/p/android/issues/detail?id=7147#c6

    0 讨论(0)
  • 2020-11-21 19:24

    I was facing the same issue today what worked for is below down

    For ANDROID STUDIO... Enable Instant Run

    In File->Preferences->Build, Execution, Deployment->Instant Run-> Check Enable Instant run for hot swap...

    Hope it helps

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