Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
194 views
in Technique[技术] by (71.8m points)

android - NoClassDefFoundError below SDK 21

I just experienced an awkward bug in my App.

On my Nexus 5/7, running android 5.0.1/5.0.2, everything works just fine. However if i try running the exact same code on a device with an earlier version (tested 4.4.4 and 4.3) I get the following error:

03-13 13:49:41.140  21714-21714/? E/dalvikvm﹕ Could not find class 'com.default.package.application.model.Appcomponent', referenced from method com.default.package.application.controller.DatabaseHandler.getScreenComponents
03-13 13:49:41.140  21714-21714/? E/dalvikvm﹕ Could not find class 'android.support.v7.app.ActionBarActivityDelegate$1', referenced from method android.support.v7.app.ActionBarActivityDelegate.<init>
03-13 13:49:41.140  21714-21714/? E/dalvikvm﹕ Could not find class 'android.support.v7.app.ActionBarActivityDelegateHC', referenced from method android.support.v7.app.ActionBarActivityDelegate.createDelegate
03-13 13:49:41.140  21714-21714/? E/dalvikvm﹕ Could not find class 'android.support.v7.app.ActionBarActivityDelegateBase', referenced from method android.support.v7.app.ActionBarActivityDelegate.createDelegate
03-13 13:49:41.150  21714-21714/? E/dalvikvm﹕ Could not find class 'android.support.v7.app.ActionBarActivityDelegate$ActionBarDrawableToggleImpl', referenced from method android.support.v7.app.ActionBarActivityDelegate.getDrawerToggleDelegate
03-13 13:49:41.150  21714-21714/? E/dalvikvm﹕ Could not find class 'android.support.v7.internal.view.SupportMenuInflater', referenced from method android.support.v7.app.ActionBarActivityDelegate.getMenuInflater
03-13 13:49:41.150  21714-21714/? E/dalvikvm﹕ Could not find class 'android.support.v7.app.ActionBarActivityDelegate$ActionBarDrawableToggleImpl', referenced from method android.support.v7.app.ActionBarActivityDelegate.getV7DrawerToggleDelegate
03-13 13:49:41.150  21714-21714/? E/AndroidRuntime﹕ FATAL EXCEPTION: main
    Process: com.default.package, PID: 21714
    java.lang.NoClassDefFoundError: android.support.v7.app.ActionBarActivityDelegateHC

I've already tried adding the support.v7 library as jar, but makes no difference. But since it works on Lollipop devices this wouldn't make sense anyway.

Could it be that there's some issue concerning the Dalvik/Art change? Or maybe the fact that I had to use com.android.support:multidex:1.0.0 since it's a rather large app.

Update: I tried removing some dependencies to get under the 65k method limit. After that the app ran on 4.4.4 and 4.3 devices. All I did for enabling multidex support was setting

multiDexEnabled true

in the defaultConfig section and adding

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

below in the dependencies section of my build.gradle.

Any idea why this causes these issues on the older android versions?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I resolved the issue by adding this to my Application Class.

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

Seems to be neccessary for android versions prior 5.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...