Android工程の方法数は64 kを超え、The number of method references in a.dex file cannot exceed 64K.

1497 ワード

最近、古いEclipseプロジェクトをAndroid Studioに転送した後、gradleでいくつかの依存を追加し、プロジェクトはmakeできますが、runが間違っていると報告しました.
Error:The number of method references in a .dex file cannot exceed 64K.
Learn how to resolve this issue at https://developer.android.com/tools/building/multidex.html

の原因となる
アイテムのメソッド数が64 kを超えているので、下請け処理が必要!
Android Studioソリューション:
Eclipseの解決方法については、対応するプラグインが必要らしい!
最初のステップ、依存関係の追加
implementation 'com.android.support:multidex:1.0.1'`

ステップ2、構成を追加します.build.gradle(app)
  • buildTypes
  •  dexOptions {
                preDexLibraries false
            }
    

    ここではbuildTypesに追加する必要があります.appが他のmoduleに依存している場合は、対応するmoudle(build.gradle)にも追加する必要があります.
  • defaultConfigで
  • を追加
    multiDexEnabled true
    

    ステップ3では、MultiDexApplicationの作成
  • カスタムアプリケーションカスタムアプリケーションがある場合は、android.support.multidex.MultiDexApplication;を継承し、attachBaseContextメソッド
  • を書き換えます.
    /**
         *     64K,      
         * fjj 2019-3-27
         * @param base
         */
        @Override
        protected void attachBaseContext(Context base) {
            super.attachBaseContext(base);
            MultiDex.install(this); //    
        }
    
  • 自分のプロジェクトにカスタムアプリケーションがない場合、カスタムも必要ない場合は、AndroidManifest.xmlapplicationの下で直接指定できます:
  • android:name="android.support.multidex.MultiDexApplication;"
    

    最後に
    これ、敬礼!