Solusi error dengan membuat multidex

Konten [Tampil]

 Isi kode Eror:


ERROR:D8: Cannot fit requested classes in a single dex file (# methods: 65767 > 65536)

com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives: 

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

at com.android.builder.dexing.D8DexArchiveMerger.getExceptionToRethrow(D8DexArchiveMerger.java:151)

at com.android.builder.dexing.D8DexArchiveMerger.mergeDexArchives(D8DexArchiveMerger.java:138)

at com.android.build.gradle.internal.tasks.DexMergingWorkAction.merge(DexMergingTask.kt:859)


Solusi :

Buka file android/app/build.gradle.


Tambahkan dependency multidex di dalam blok dependencies:


groovy

Copy code

implementation 'androidx.multidex:multidex:2.0.1'

Di dalam blok android tambahkan konfigurasi multidex:


groovy

Copy code

android {

  defaultConfig {

    // ...

    multiDexEnabled true

  }

  // ...

}

Buat class baru yang mewarisi MultiDexApplication:


dart

Copy code

import androidx.multidex.MultiDexApplication;


class MyApplication extends MultiDexApplication {

  // ...

}

Buka file android/app/src/main/AndroidManifest.xml dan tambahkan atribut android:name pada elemen <application> untuk mengarahkan ke class aplikasi yang Anda buat:


xml

Copy code

<application

  android:name=".MyApplication"

  // ...

>

  <!-- Aktivitas dan konfigurasi lainnya -->

</application>

Setelah langkah-langkah di atas selesai, Anda dapat mencoba menjalankan aplikasi lagi. Masalah "Cannot fit requested classes in a single dex file" seharusnya teratasi dengan menggunakan multidex.


Jika masalah masih berlanjut atau Anda mengalami kesulitan dalam mengimplementasikan solusi ini, Anda dapat merujuk ke dokumentasi resmi Android tentang multidex di tautan berikut: https://developer.android.com/tools/building/multidex.html 

Previous Post Next Post