Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multidex installation failure

I'm using CircledImageView library. It works fine on lollipop+ android versions. But in kitkat it's crashing. So after searching on google. I found that i have to implement multidex in my app.

So this my application class.

public class FireApp extends Application {

    @Override
    public void onCreate() {
        super.onCreate();
        Firebase.setAndroidContext(this);
        Fresco.initialize (this);
    }

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

And in build.gradle under defaultconfig MultiDexEnabled is true

multiDexEnabled true

But when I run the app, I get the following error.

java.lang.NoSuchFieldException: Field dexElementsSuppressedExceptions not found in class dalvik.system.PathClassLoader
 at android.support.multidex.MultiDex.findField(MultiDex.java:288)
 at android.support.multidex.MultiDex.access$300(MultiDex.java:57)
 at android.support.multidex.MultiDex$V19.install(MultiDex.java:390)
 at android.support.multidex.MultiDex$V19.access$000(MultiDex.java:369)
 at android.support.multidex.MultiDex.installSecondaryDexes(MultiDex.java:242)
 at android.support.multidex.MultiDex.install(MultiDex.java:161)
 at android.support.multidex.MultiDexApplication.attachBaseContext(MultiDexApplication.java:39)
 at com.buckydroid.anonchat.FireApp.attachBaseContext(Unknown Source)
 at android.app.Application.attach(Application.java:182)
 at android.app.Instrumentation.newApplication(Instrumentation.java:991)
 at android.app.Instrumentation.newApplication(Instrumentation.java:975)
 at android.app.LoadedApk.makeApplication(LoadedApk.java:511)
 at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4564)
 at android.app.ActivityThread.access$1500(ActivityThread.java:139)
 at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1353)
 at android.os.Handler.dispatchMessage(Handler.java:102)
 at android.os.Looper.loop(Looper.java:149)
 at android.app.ActivityThread.main(ActivityThread.java:5268)
 at java.lang.reflect.Method.invokeNative(Native Method)
 at java.lang.reflect.Method.invoke(Method.java:515)
 at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:609)
 at dalvik.system.NativeStart.main(Native Method)
like image 345
Doge Avatar asked Mar 22 '17 11:03

Doge


People also ask

What is the purpose of multidex?

Multidex support for Android 5. dex files and compiles them into a single . oat file for execution by the Android device. Therefore, if your minSdkVersion is 21 or higher multidex is enabled by default, and you do not need the multidex library. For more information on the Android 5.0 runtime, read ART and Dalvik.

What is multidex Android?

Getting past this limit requires that you configure your app build process to generate more than one DEX file, known as a multidex configuration. So, the feature is: it allows your complex app to compile. The scenarios for using it are when your app fails to compile due to hitting the 64K DEX method reference limit.

How do I enable multidex in Flutter app?

The multidex support is enabled automatically. If your app supports Android SDK versions below 21, and it exceeds the 64K method limit, simply pass the --multidex flag to flutter build appbundle or flutter build apk and your app will support multidex.

What is multidex error?

In Android, the compiler converts our source code into DEX(Dalvik Executable) file. So, in this blog, we will learn about Dex and Multidex in Android. Especially, this blog is for those Android developers who get 64K method limit exceeded error while building APK. This error comes due to DEX.


2 Answers

Try including compile 'com.android.support:multidex:1.0.1' in your build.gradle file.

like image 153
Benjamin James Drury Avatar answered Oct 18 '22 19:10

Benjamin James Drury


check following steps this steps

1) Add dependency in your build.gradle file :

compile 'com.android.support:multidex:1.0.0'

2) Enable multidex and set heap size

defaultConfig {
    applicationId "your package name"
    minSdkVersion 19
    targetSdkVersion 23
    versionCode 1
    versionName "1.0"
    multiDexEnabled true
}

dexOptions {
    javaMaxHeapSize "4g"
}

3) In Application class add this

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

4) Add this in your manifest in <application> tag :

android:name=".YourApplicationClassName"
like image 34
Malik Motani Avatar answered Oct 18 '22 19:10

Malik Motani