RoboGuice 3.0 NoClassDefFoundError: roboguice.inject.ContextScopedRoboInjector
Asked Answered
A

2

9

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>
Anta answered 13/1, 2016 at 4:43 Comment(6)
are you using proguard in your build.gradle ?Somersomers
Its used in release build type and not in debug, I am getting this error while debug run itselfAnta
Seems like a multidex issue. Are you using multidex for your debug builds?Wisniewski
Yes, I am using multidex, I guess my app only works for Android 5.0 and above and not below because of this. Probably RoboGuice is adding a lot of function calls internally. I will try updating my application and get back. Thanks for pointing out this.Anta
@Anta can here i gave my answer still you got things not solved can you please post your build.gradle file ? is there anything declaration of RoboGuice on app start up like on application class ?Zwick
@Anta can you please post your build.gradle file..?Zwick
Z
3

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.

Zwick answered 23/1, 2016 at 7:34 Comment(5)
I tried this but it didn't help due to space issue, as it stated cannot create Java Virtual Machine with given config.Anta
Which ide are you using..? If it's studio thn can you pls post your build.gradle.Zwick
I am using Android Studio 1.5.1, my issue just got resolved by adding android:name="android.support.multidex.MultiDexApplication" to <application in AndroidManifest.xml this was only thing that I missed in configuration.Anta
But just by adding MultiDexApplication to manifest problem won't resolved for 4.1 device you need to create Application class which will extend MultiDexApplication and need to install multidex in attachBasContext method.. Thn declare tht created application class in manifest..Check last code block MyAppClass in answer... nd thts absolutely fine if that magic worked for you.. :)Zwick
MultiDex was already enabled in my build.gradle, MultiDex.install is required for TestRunner not for all time. Thanks for your help :)Anta
A
1

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.

Aperient answered 20/1, 2016 at 11:9 Comment(1)
No luck other this too.Anta

© 2022 - 2024 — McMap. All rights reserved.