RoboGuice 3.0 NoClassDefFoundError: roboguice.inject.ContextScopedRoboInjector

两盒软妹~` 提交于 2020-01-03 08:32:37

问题


This is not always seen but seen on particular API 14 and 19.

Below is the stacktrace

java.lang.NoClassDefFoundError: roboguice.inject.ContextScopedRoboInjector
    at roboguice.RoboGuice.getInjector(RoboGuice.java:197)
    at roboguice.activity.RoboActivity.onCreate(RoboActivity.java:90)
    at com.bnmcombines.galleryflavors.Launcher.onCreate(Launcher.java:71)
    at android.app.Activity.performCreate(Activity.java:5343)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1088)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2343)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2441)
    at android.app.ActivityThread.access$900(ActivityThread.java:151)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1354)
    at android.os.Handler.dispatchMessage(Handler.java:110)
    at android.os.Looper.loop(Looper.java:193)
    at android.app.ActivityThread.main(ActivityThread.java:5345)
    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:828)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:644)
    at dalvik.system.NativeStart.main(Native Method)

Already an issue is logged with RoboGuice 3.0: https://github.com/roboguice/roboguice/issues/328

But no response and we are currently blocked.

Issue Resolved

I referred MultiDex Document more carefully this time and updated my AndroidManifest.xml to below that I had missed

<application
        ...
        android:name="android.support.multidex.MultiDexApplication">
        ...
    </application>
</manifest>

回答1:


From the git link which you posted in answer

Getting this error on API Level 14 and API Level 19 devices. While trying to search for Class, I see that this class is available, but still getting NoClassDefFoundException which is weird. This is happening only under certain case not always

This error will come because of MultiDexApplication .I have face this kind of issue with some other library not same library but some other library.It will error of the RoboGuice library because its initilization of app start up where dex(in which your RoboGuice library code is converted to dex) file is not to set(install).

To resolve that you need to handle Multiple Dex file. with the help of applicaiton build.gradle & Application class

below changes which is required in build.gradle file

dexOptions {
        incremental true
        // here heap size give 4g i got this thing from https://groups.google.com/forum/#!topic/adt-dev/P_TLBTyFWVY

        javaMaxHeapSize "4g"
    }


dependencies {
     compile 'com.android.support:multidex:1.0.1'
    //    your dependencies which you are using.

}

Entire build.gradle

apply plugin: 'com.android.application'
repositories {
    mavenCentral()// for new android studio version it can be jcenter()

}
configurations {
//    all*.exclude group: 'com.android.support', module: 'recyclerview-v7'
}

android {
    signingConfigs {
        /*
        releasebuild {
            keyAlias 'hellotest'
            keyPassword 'hellotest'
            storeFile file('path to keystore')
            storePassword 'hellotest'
        }
        */
    }
    compileSdkVersion 'Google Inc.:Google APIs:22'
    buildToolsVersion '23.0.0'
    /* if you got error regarding duplicate file of  META-INF/LICENSE.txt from jar file
    packagingOptions {
        exclude 'META-INF/LICENSE.txt'
    }
    */
    dexOptions {
        jumboMode = true
        incremental true
        // here heap size give 4g i got this thing from https://groups.google.com/forum/#!topic/adt-dev/P_TLBTyFWVY

        javaMaxHeapSize "4g"
    }
    defaultConfig {
        multiDexEnabled true
        applicationId "com.myapp.packagenme"
        minSdkVersion 17
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            signingConfig signingConfigs.releasebuild
        }
        debug {
            signingConfig signingConfigs.releasebuild
        }
    }
}

dependencies {
     compile 'com.android.support:multidex:1.0.1'
    //    your dependencies which you are using.

}

If your app uses extends the Applicationclass, you can override the attachBaseContext() method and call MultiDex.install(this) to enable multidex. To install multipledex file context using Applicaiton class which should extends MultiDexApplication

public class MyAppClass extends MultiDexApplication{
@Override
    protected void attachBaseContext(Context newBase) {
        MultiDex.install(newBase);
        super.attachBaseContext(newBase);
    }
}

Let me know if anything.




回答2:


I propose to do the following -

  1. Check if this is a 65k methods limit (multidex) issue by trying to run a release build with Proguard removing unused functions and reducing the number of functions in the dex.

  2. java.lang.NoClassDefFoundError can also be caused when exceptions are thrown during static variable/object initialization. Check if you are using a/inheriting from a RoboGuice class or using initialization code with static objects or code blocks. The problem may come from there.

Also, take a look at RoboGuice 3.0 NoClassDefFoundError: AnnotationDatabaseImpl , it may help you (despite that the error the user is getting is about another class, they initialization is that of a static object).

good luck.



来源:https://stackoverflow.com/questions/34758559/roboguice-3-0-noclassdeffounderror-roboguice-inject-contextscopedroboinjector

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!