Android Studio 4.0升级后无法解析MultiDexApplication问题求助
Hey, I’ve faced similar hiccups after bumping Android Studio and Gradle versions, so let’s break down the fixes to get your MultiDex setup back on track:
1. Verify Module-level Build.gradle Configurations
First, make sure your module's build.gradle has the correct MultiDex settings:
- Enable MultiDex in the
defaultConfigblock:android { defaultConfig { // ... your existing configs (minSdkVersion, targetSdkVersion, etc.) multiDexEnabled true } } - Ensure you’re using the AndroidX-compatible MultiDex dependency (old support library versions won’t work with AndroidX):
dependencies { // ... other dependencies implementation 'androidx.multidex:multidex:2.0.1' // Use the latest stable version if available }
2. Check Your Custom Application Class
Double-check the import and inheritance in your MyApplication class:
- Make sure you’re importing the AndroidX variant of
MultiDexApplication:import androidx.multidex.MultiDexApplication; public class MyApplication extends MultiDexApplication { @Override public void onCreate() { super.onCreate(); // Your app initialization logic here } } - If your app already inherits from another
Applicationsubclass (and you can’t switch toMultiDexApplication), use this alternative approach by overridingattachBaseContext:import android.app.Application; import android.content.Context; import androidx.multidex.MultiDex; public class MyApplication extends Application { @Override protected void attachBaseContext(Context base) { super.attachBaseContext(base); MultiDex.install(this); } }
3. Clear Cache & Rebuild the Project
Gradle caches can sometimes cause dependency resolution issues after version upgrades:
- Go to
File > Invalidate Caches / Restartand confirm the action. - Once Android Studio restarts, run
Build > Clean Projectfollowed byBuild > Rebuild Project.
4. Validate AndroidX Settings in Gradle.properties
Ensure your project is properly configured for AndroidX by checking these lines in the root gradle.properties file:
android.useAndroidX=true android.enableJetifier=true
These settings ensure all dependencies (including MultiDex) are mapped to their AndroidX equivalents.
After going through these steps, your MultiDexApplication import should resolve correctly, and your custom application class should work as expected.
内容的提问来源于stack exchange,提问作者Nightfury

