Configure Multidex on React Native

2024-09-18 hit count image

Let's see how to configure Multidex on Android in React Native project.

Outline

Sometimes, the error message below appeared on React Native.

Cannot fit requested classes in single dex file

To solve this error, we need to set Multidex on React Native project. Let’s see how to configure Multidex on React Native project.

Gradle setting

To configure Multidex for Android on React Native project, open android/app/build.gradle file and modify it like below.

android {
    defaultConfig {
        ...
        versionName "1.0"
        multiDexEnabled true
    }
    ...
}

dependencies {
  def multidex_version = "2.0.1"
  implementation 'androidx.multidex:multidex:$multidex_version'
}

Java setting

After modifying Gradle file like above, open MainApplication.java file and modify it like below.

import androidx.multidex.MultiDexApplication;

public class MainApplication extends MultiDexApplication implements ReactApplication {
  ...
}

Completed

Done! we’ve seen how to set Multidex on React Native. After configuration, when you execute the command below, you can see the problem is solved.

npm run android

I hope this blog post is helpful for the developers to develop Android project on React Native.

Was my blog helpful? Please leave a comment at the bottom. it will be a great help to me!

App promotion

You can use the applications that are created by this blog writer Deku.
Deku created the applications with Flutter.

If you have interested, please try to download them for free.

Posts