简体   繁体   中英

AndroidRuntime Caused by: java.lang.ClassNotFoundException: Didn't find class “android.support.multidex.MultiDexApplication”

I have an issue with launching my app in Release mode.

I have enabled MultiDex for Debug and Release modes. When deploying in Debug mode, my app is working fine and everything OK. But when I launch it Release mode, it crashes at startup. Here's a Device Log:

错误

Android manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
android:versionName="17.2" android:versionCode="1" 
android:installLocation="auto" package="com.myapp">
  <uses-sdk android:minSdkVersion="19" android:targetSdkVersion="28" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <application android:label="Test Application" android:largeHeap="true" android:icon="@drawable/AppIcon" android:supportsRtl="true">
        <provider android:name="android.support.v4.content.FileProvider" android:authorities="${applicationId}.provider" android:exported="false" android:grantUriPermissions="true">
        <meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/provider_paths" />
    </provider>
    </application>
</manifest>

Make your Application extend MultiDexApplication. If you don't have one already just create a BaseApplication class like so:

public class BaseApplication extends MultiDexApplication {
    @Override
    public void onCreate() {
        super.onCreate();
    }

    @Override
    protected void attachBaseContext(Context base) {
    super.attachBaseContext(base);
    MultiDex.install(this);
}

}

also, add the following to your build.gradle:

multiDexEnabled true

for your dependencies:

dependencies {
    implementation 'androidx.multidex:multidex:2.0.1'
}

or if not using AndroidX

dependencies {
  implementation 'com.android.support:multidex:1.0.3'
}

Finally in your manifest add within your application tag:

android:name="android.support.multidex.MultiDexApplication"

or

android:name="androidx.multidex.MultiDexApplication"

if you've migrated to AndroidX

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM