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.
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>
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.
I propose to do the following -
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With