Android Studio E/dalvikvm﹕ Could not find class &#

2020-07-06 07:57发布

问题:

Hello I'm getting this error using Android Studio on runtime but only on devices with an SDK version <= 19. Everything compiles ok but I get this error on my databaseHelper Class.

java.lang.NoClassDefFoundError:

Here is my app build.gradle:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion '23.0.1'
    useLibrary  'org.apache.http.legacy'

    defaultConfig {
        minSdkVersion 11
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
        multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled true
        }
    }
}



dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.google.android.gms:play-services:7.8.0'
    compile 'com.android.support:appcompat-v7:23.0.1'
    compile 'com.github.johnpersano:supertoasts:1.3.4@aar'
    compile 'com.readystatesoftware.systembartint:systembartint:1.0.3'
    compile 'com.navercorp.pulltorefresh:library:3.2.0@aar'
    compile 'com.parse.bolts:bolts-android:1.2.1'
    compile 'com.j256.ormlite:ormlite-android:4.48'
    compile 'com.j256.ormlite:ormlite-core:4.48'
}

My databaseHelper class extends OrmLiteSqliteOpenHelper Everything was working fine while my compileSdkVersion was at 19 Here is what I updated:

  • gradle: classpath 'com.android.tools.build:gradle:1.1.0' > 1.3.0
  • sdk Version: compileSdkVersion 19 > 23
  • appcompat: com.android.support:appcompat-v7:19.0.1 > 23
  • play-services

My databaseHelper Class is in the same package than other Classes which work fine !

Thank you for your help

回答1:

As you have multiDexEnabled true in your build.gradle. Make sure your application class is extending MultiDexApplication instead of the Application class.

Alternatively, as suggested in the docs, you can add the following method to your application class.

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


回答2:

I've found the problem. MultiDex is not supported corretly prior to lollypop. Once i removed the additional libraries and remove multidex setting on gradle everything started to work fine.

remove.

 multiDexEnabled true 

Regards



回答3:

I had the same issue some time a, try to turn off ProGuard

minifyEnabled false