RoboSpice上的NoClassDefFoundError

时间:2015-08-07 23:35:29

标签: android noclassdeffounderror robospice

最近我将我的Android项目从Eclipse ADT迁移到Android Studio,这有点棘手,该项目使用RoboSpice(1.4.6)并在Android API 22上运行,但是当我尝试在真实设备上运行它时(Android) API 14)它抛出NoClassDefFoundError异常。这是我的堆栈:

08-07 18:14:13.392  31254-31254/com.mypackage.myApp E/dalvikvm﹕ Could not find class 'com.octo.android.robospice.priority.PriorityFuture', referenced from method com.octo.android.robospice.priority.PriorityThreadPoolExecutor.newTaskFor
08-07 18:14:13.393  31254-31254/com.mypackage.myApp E/dalvikvm﹕ Could not find class 'com.octo.android.robospice.priority.PausablePriorityBlockingQueue', referenced from method com.octo.android.robospice.priority.PausableThreadPoolExecutor.<init>
08-07 18:14:13.394  31254-31254/com.mypackage.myApp E/dalvikvm﹕ Could not find class 'com.octo.android.robospice.priority.PausablePriorityBlockingQueue', referenced from method com.octo.android.robospice.priority.PausableThreadPoolExecutor.<init>
08-07 18:14:13.394  31254-31254/com.mypackage.myApp E/dalvikvm﹕ Could not find class 'com.octo.android.robospice.priority.PausablePriorityBlockingQueue', referenced from method com.octo.android.robospice.priority.PausableThreadPoolExecutor.pause
08-07 18:14:13.394  31254-31254/com.mypackage.myApp E/dalvikvm﹕ Could not find class 'com.octo.android.robospice.priority.PausablePriorityBlockingQueue', referenced from method com.octo.android.robospice.priority.PausableThreadPoolExecutor.resume
08-07 18:14:13.396  31254-31254/com.mypackage.myApp E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.NoClassDefFoundError: com.octo.android.robospice.priority.PausablePriorityBlockingQueue
        at com.octo.android.robospice.priority.PausableThreadPoolExecutor.<init>(PausableThreadPoolExecutor.java:25)
        at com.octo.android.robospice.priority.PriorityThreadPoolExecutor.<init>(PriorityThreadPoolExecutor.java:23)
        at com.octo.android.robospice.priority.PriorityThreadPoolExecutor.getPriorityExecutor(PriorityThreadPoolExecutor.java:35)
        at com.octo.android.robospice.SpiceService.getExecutorService(SpiceService.java:191)
        at com.octo.android.robospice.SpiceService.onCreate(SpiceService.java:107)
        at com.octo.android.robospice.SpringAndroidSpiceService.onCreate(SpringAndroidSpiceService.java:25)
        at android.app.ActivityThread.handleCreateService(ActivityThread.java:2504)
        at android.app.ActivityThread.access$1600(ActivityThread.java:149)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1382)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:153)
        at android.app.ActivityThread.main(ActivityThread.java:4987)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:511)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:821)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:584)
        at dalvik.system.NativeStart.main(Native Method)

我想我需要一个额外的jar依赖,我在网上搜索了很多,但希望你能帮助我。

编辑:11/8月/ 15

Root gradle

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.2.3'
    }
}

模块gradle:我已经尝试过只使用jar(编译文件树和逐个编译)以及通过Maven repo。

apply plugin: 'com.android.application'

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    /*compile files('libs/android-support-v4.jar')
                compile files('libs/robospice-1.4.6.jar')
                compile files('libs/robospice-cache-1.4.6.jar')
                compile files('libs/spring-android-core-1.0.1.RELEASE.jar')
                compile files('libs/spring-android-rest-template-1.0.1.RELEASE.jar')
                compile files('libs/robospice-spring-android-1.4.6.jar')
                compile files('libs/itextg-5.4.4.jar')
                compile files('libs/mpandroidchartlibrary-1-7-0.jar')
                compile files('libs/commons-lang3-3.1.jar')
                compile files('libs/jackson-mapper-asl-1.9.11.jar')
                compile files('libs/jackson-core-asl-1.9.11.jar')
                compile files('libs/gson-2.3.jar')
                compile files('libs/core-2.3.0.jar')
                compile files('libs/ksoap2-android-assembly-3.3.0-jar-with-dependencies.jar')*/
    //compile 'com.octo.android.robospice:robospice:1.4.14'
    compile project(':module1')
    compile project(':module2')
    compile project(':module3')
    compile project(':module4')
    compile project(':module5')
    compile project(':module6')
}

android {
    compileSdkVersion 14
    buildToolsVersion '22.0.1'
    defaultConfig {
        // Enabling multidex support.
        multiDexEnabled true
    }
    packagingOptions {
        exclude 'META-INF/DEPENDENCIES.txt'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/notice.txt'
        exclude 'META-INF/license.txt'
        exclude 'META-INF/dependencies.txt'
        exclude 'META-INF/LGPL2.1'
        exclude 'META-INF/ASL2.0'
    }
    sourceSets {
        main {
            manifest.srcFile 'AndroidManifest.xml'
            java.srcDirs = ['src']
            resources.srcDirs = ['src']
            aidl.srcDirs = ['src']
            renderscript.srcDirs = ['src']
            res.srcDirs = ['res']
            assets.srcDirs = ['assets']
        }
        // Move the tests to tests/java, tests/res, etc...
        instrumentTest.setRoot('tests')

        // Move the build types to build-types/<type>
        // For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
        // This moves them out of them default location under src/<type>/... which would
        // conflict with src/ being used by the main source set.
        // Adding new build types or product flavors should be accompanied
        // by a similar customization.
        debug.setRoot('build-types/debug')
        release.setRoot('build-types/release')
    }
    productFlavors {
    }
}

1 个答案:

答案 0 :(得分:0)

您在jar的评论部分使用robospice-1.4.6.jar,此版本可能不包含您遇到错误的类。由于第一个依赖行compile fileTree(dir: 'libs', include: ['*.jar'])libs目录中的每个jar文件都将包含在类路径中。

我建议考虑仅使用Maven依赖项管理,从libs目录中删除与RoboSpice相关的所有jar文件,并仅包含您实际使用的RoboSpice扩展名(似乎这对您来说是'com.octo.android.robospice:robospice-spring-android:1.4.14'情况)。