16

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)
tynn
  • 38,113
  • 8
  • 108
  • 143
Doge
  • 853
  • 11
  • 35
  • 1
    First of all, no need to both extend the MultiDexApplication and call MultiDex.install(this). Choose one of them. On which device are you having this error? – Alex Lipov Mar 23 '17 at 06:50
  • I'm getting this error on my zenfone5 android kitkat @AlexLipov – Doge Mar 23 '17 at 09:28
  • Still i got no solution :( – Doge Mar 24 '17 at 18:33
  • I don't have such device, so I can't test. If you'll check the source, you'll see that the library tries to find the [dexElementsSuppressedExceptions](https://android.googlesource.com/platform/frameworks/multidex/+/android-7.1.1_r23/library/src/android/support/multidex/MultiDex.java#428) field, which is a private field of [DexPathList](https://android.googlesource.com/platform/libcore/+/kitkat-mr2.2-release/dalvik/src/main/java/dalvik/system/DexPathList.java#70) class. Which (exact) Android version your Zenfone 5 device is running? – Alex Lipov Mar 29 '17 at 19:46
  • If it's API level 19, then Asus probably altered the internal implementation of DexPathList (at least this is what it seems from your exception). If this is the case - I'm curious how other multi-dex applications work on your device (i.e., does Uber run on your device?).. – Alex Lipov Mar 29 '17 at 20:11
  • No man, It's some problem in code. I tried in all pre lolipop devices on virtual testing offered by firebase and same error @AlexLipov – Doge Apr 06 '17 at 19:23
  • Can you share your gradle file? – azizbekian Apr 06 '17 at 20:09
  • please check [this](http://stackoverflow.com/a/43274600/3960700) – Stephen Apr 07 '17 at 09:41
  • try [this](http://stackoverflow.com/a/41479407/6478047) solution once – Manohar Apr 07 '17 at 10:12
  • 1
    I'd be interested in the logs with tag `"MultiDex"` and message `"Exception in makeDexElement"` just before your actual error. – tynn Apr 10 '17 at 13:29
  • 1
    Maybe related https://code.google.com/p/android/issues/detail?id=210188 – tynn Apr 10 '17 at 14:42
  • Enable Dex in you default config file "multiDexEnabled true" – sivaprakash Apr 13 '17 at 18:10
  • I came across the same problem with my app and has solved it. For my case, this error appeared after I stopped an on-going gradle build process during my first build. To solve it, I cleaned the entire project and rebuild it again. Not sure why, but it solved the error, so maybe anyone who came across this same problem could try my solution – karansky Mar 13 '18 at 02:50

10 Answers10

3

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

Benjamin James Drury
  • 2,353
  • 1
  • 14
  • 27
3

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"
Maddy
  • 4,525
  • 4
  • 33
  • 53
2
  1. Make sure the application declared in the manifest file extends MultiDexApplication.
  2. Make sure your build.gradle file enabled multidexing and included the compile 'com.android.support:multidex:1.0.1' package dependency.
  3. Make sure your are not being trolled by Android Studio fast build. You can remove all build directories and install using the application using command line.
  4. If your application has flavours, make sure the installed flavor is using MultiDexApplication
JP Ventura
  • 5,564
  • 6
  • 52
  • 69
  • 1
    As mentioned by @alex-lipov, remove `MultiDex.install(this)` make sure your application `FireApp` is inheriting from `MultiDexApplication`, not `Application` and also `android:name=".FireApp"`. Usually I repeat this check before start looking for other insane multidexing bugs ;-) – JP Ventura Apr 06 '17 at 19:56
  • 2
    Having `MultiDex.install(this)` is functionally equivalent to extending `MultiDexApplication`. – Eugen Pechanec Apr 13 '17 at 17:32
  • 1
    The 3rd point of "remove all build directories". The comment by "JP Ventura" of removing MultiDex.install(this) with method in Application class worked for me. I had other things in proper place. – SHS Aug 23 '17 at 11:06
2

Try this Inside your app level build.gradle file put the following line of code

android{
      //compielsdkVersion..
      //..
      //..
      vectorDrawables.useSupportLibrary = true
}

and in the Activity.java that you are using the CircularImageView put the following static block on the top of onCreate() method like this

    //...
   //....
    static {
            AppCompatDelegate.setCompatVectorFromResourcesEnabled(true);
        }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
   //...
   //...
MrCurious
  • 150
  • 3
  • 11
1

previous solutions are ok but one missing thing MultiDexApplication

public class FireApp extends MultiDexApplication 
amorenew
  • 10,760
  • 10
  • 47
  • 69
0

Add this line in your application tag in your manifest

android:name="android.support.multidex.MultiDexApplication"
R.R.M
  • 780
  • 4
  • 10
  • 2
    But under application tag. I have added this android:name=".FireApp" – Doge Mar 22 '17 at 11:16
  • Can't you replace that line with line which I have given to you? – R.R.M Mar 22 '17 at 11:18
  • 4
    This answer is misleading. The OP already configured his application to extend MultiDexApplication. You just offer another way to do the same thing (or even worse, you're asking him to not use his FireApp application class which may have custom logic). – Alex Lipov Mar 23 '17 at 06:54
0

On API 19 and 20, the library was trying to save "suppressed exceptions" in the loader.dexElementsSuppressedExceptions.

But the field is not there, it's in DexPathList, so the correct path is loader.pathList.dexElementsSuppressedExceptions.

Google has fixed it: https://android.googlesource.com/platform/frameworks/multidex/+/74e66b8013b5b9002f67e53825c189a18597b1e8%5E%21/#F0

You need to update multidex version to 1.0.2+.

jkdev
  • 11,360
  • 15
  • 54
  • 77
hezi
  • 1
0

I was facing the same problem on a Sony device running Android 4.3 (API 18) on debug build (release was ok). After trying every single solution out there and making sure to do everything right I was still not able to fix the issue.

As I was building and installing my APK using Android Studio for several devices I accidently found that if I try to build it for a Lollipop device once and then build it for an older version (below KitKat) it will run without the annoying MultiDex installation failed error.

Note that my own device which I use most often to build and test the app runs API 28.

Sdghasemi
  • 5,370
  • 1
  • 34
  • 42
-2

this is a error in kitkat multidex,u can override the V19.install, cause dexElementsSuppressedExceptions is the field in dexPathList, not in loader. However, there is exception when dalvik do makeDexElements, but you get the wrong message insteadenter image description here

-3

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