「dex file cannot exceed 64K.」で動かないときの対応

calendar

エラーメッセージ:
「 The number of method references in a .dex file cannot exceed 64K.」の回避方法

「app」レベルの「build.gradle」ファイルの編集
minSdkVersion が 21 以上の場合は、multiDexEnabled を true に設定する
// minSdkVersion が 21 以上の場合
// 「app」レベルの「build.gradle」ファイルを編集
...
android {
  ...
  defaultConfig {
    ...
    multiDexEnabled true
  }
  ...
}

minSdkVersion が 20 以下の場合は、multiDexEnabled を true にして、Multidex ライブラリを追加
// minSdkVersion が 20 以下の場合
// 「app」レベルの「build.gradle」ファイルを編集
...
android {
  ...
  defaultConfig {
    ...
    multiDexEnabled true
  }
  ...
}
...
dependencies {
  implementation 'com.android.support:multidex:1.0.3'
  ...
}
「manifests/AndroidManifest.xml」ファイルの編集
// minSdkVersion が 20 以下の場合
// 「AndroidManifest.xml」ファイルを編集
...
    <application
            android:name="android.support.multidex.MultiDexApplication" >
        ...
    </application>

AndroidXを利用の場合は、「android.support.multidex.MultiDexApplication」が「androidx.multidex.MultiDexApplication」になります。

参考URL:
64K を超えるメソッドを使用するアプリの設定
https://developer.android.com/studio/build/multidex.html?hl=JA

この記事をシェアする

コメント

コメントはありません。

down コメントを残す