You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Android Studio 4.0升级后无法解析MultiDexApplication问题求助

解决升级Android Studio 4.0 & Gradle 6.1.1后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 defaultConfig block:
    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 Application subclass (and you can’t switch to MultiDexApplication), use this alternative approach by overriding attachBaseContext:
    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 / Restart and confirm the action.
  • Once Android Studio restarts, run Build > Clean Project followed by Build > 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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.07 19:33:00