# java.lang.RuntimeException: Unable to instantiate application com.example.MyApp: java.lang.ClassNotFoundException: Didn't find class "com.example.MyApp" on path: DexPathList[[zip file "/data/app/..."],nativeLibraryDirectories=[/data/app/...]]

- **ID:** `android/multidex-keep-cannot-find-class`
- **Domain:** android
- **Category:** runtime_error
- **Verification:** ai_generated
- **Fix Rate:** 82%

## Root Cause

MultiDex application class not loaded because the main dex file does not include the custom Application class; MultiDex.install() may not be called early enough or using legacy multidex without proper keep configuration.

## Version Compatibility

| Version | Status | Introduced | Deprecated |
|---------|--------|------------|------------|
| Android 4.4 - 14 | active | — | — |
| Android Gradle Plugin 3.6 - 8.2 | active | — | — |
| multidex:1.0.3 | active | — | — |

## Workarounds

1. **Add the custom Application class to the main dex keep list by creating a file 'multidex.keep' in the app directory with content: 'com/example/MyApp.class', then in build.gradle: 'multiDexKeepFile file('multidex.keep')'.** (85% success)
   ```
   Add the custom Application class to the main dex keep list by creating a file 'multidex.keep' in the app directory with content: 'com/example/MyApp.class', then in build.gradle: 'multiDexKeepFile file('multidex.keep')'.
   ```
2. **Override attachBaseContext() in the Application class to call MultiDex.install() before super.attachBaseContext(): 'public class MyApp extends Application { @Override protected void attachBaseContext(Context base) { super.attachBaseContext(base); MultiDex.install(this); } }'** (90% success)
   ```
   Override attachBaseContext() in the Application class to call MultiDex.install() before super.attachBaseContext(): 'public class MyApp extends Application { @Override protected void attachBaseContext(Context base) { super.attachBaseContext(base); MultiDex.install(this); } }'
   ```
3. **Use 'androidx.multidex:multidex:2.0.1' and enable multidex in build.gradle: 'defaultConfig { multiDexEnabled true }' and set minSdkVersion to 21 if possible.** (95% success)
   ```
   Use 'androidx.multidex:multidex:2.0.1' and enable multidex in build.gradle: 'defaultConfig { multiDexEnabled true }' and set minSdkVersion to 21 if possible.
   ```

## Dead Ends

- **** — The Application class must be explicitly kept in the main dex; simply adding other classes does not solve the instantiation failure. (50% fail)
- **** — If the app still targets lower API levels or uses legacy multidex, the error persists; also, this may not be feasible for apps supporting older devices. (50% fail)
- **** — The root cause is a missing class in the main dex, which cannot be fixed by a simple rebuild; the multidex keep configuration is still incorrect. (50% fail)
