应用程序在API级别低于21时崩溃,这是由SQLite类引起的

时间:2015-07-23 07:47:04

标签: android sqlite

每当我尝试在21以下的Android API级别上运行应用时,我都会遇到异常NoClassDefFoundError

07-23 03:52:53.410  11681-11681/com.xyz.abc E/AndroidRuntime﹕ FATAL EXCEPTION: main
    Process: com.xyz.abc, PID: 11681
    java.lang.NoClassDefFoundError: com.xyz.abc.database.DB$DBHelper
            at com.xyz.abc.database.DB.<init>(DB.java:27)
            at com.xyz.abc.abcApp.onCreate(abcApp.java:39)
            at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1007)
            at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4328)
            at android.app.ActivityThread.access$1500(ActivityThread.java:135)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5001)
            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:785)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
            at dalvik.system.NativeStart.main(Native Method)

这是我的gradle脚本

apply plugin: 'com.android.application'

android {
    compileSdkVersion 21
    buildToolsVersion "21.1.1"

    defaultConfig {
        applicationId "com.xyz.abc"
        minSdkVersion 15
        targetSdkVersion 21
        versionCode 1
        versionName "1.0"
        multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        debug {
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:22.2.0'
    compile 'com.android.support:recyclerview-v7:22.2.0'
    compile 'org.lucasr.dspec:dspec:0.1.1'
    compile 'com.mcxiaoke.volley:library:1.0.+'
    compile 'com.telly:mrvector:0.2.0'
    compile 'com.oguzdev:CircularFloatingActionMenu:1.0.2'
    compile 'me.tatarka.support:jobscheduler:0.1.1'
    compile 'jp.wasabeef:recyclerview-animators:1.1.0'
    compile 'com.nineoldandroids:library:2.4.0'
    compile 'com.daimajia.easing:library:1.0.1@aar'
    compile 'com.daimajia.androidanimations:library:1.1.3@aar'
    compile 'com.pkmmte.view:circularimageview:1.1'
    compile 'com.android.support:gridlayout-v7:22.2.0'
    compile 'com.android.support:design:22.2.0'
    compile 'com.android.support:cardview-v7:22.2.0'
    compile 'com.google.android.gms:play-services:7.5.0'
    compile 'com.github.bumptech.glide:glide:3.5.2'

    compile 'com.marvinlabs:android-floatinglabel-widgets:1.6.1@aar'
    compile 'com.android.support:support-annotations:22.2.0'
    compile 'com.amazonaws:aws-android-sdk-core:2.+'
    compile 'com.amazonaws:aws-android-sdk-cognito:2.+'
    compile 'com.amazonaws:aws-android-sdk-s3:2.+'
    compile 'com.amazonaws:aws-android-sdk-ddb:2.+'

    compile 'com.parse.bolts:bolts-android:1.+'
}

这是我的第一个Android应用程序,我想我在某个地方犯了一些愚蠢的错误。请帮帮我

1 个答案:

答案 0 :(得分:0)

我发现了真正的问题。这是multidex的问题。 Android SDK Build Tools 21.1及更高版本支持multidex作为构建配置的一部分,因此它在21及以上的设备上运行顺畅。

我必须添加com.android.support:multidex:1.0.0库并进行一些代码更改,以确保应用程序在较低版本上运行而没有任何障碍。

有关详细信息,请访问https://developer.android.com/tools/building/multidex.html