java.lang.NoClassDefFoundError: weborb.types.Types (and java.lang.ExceptionInInitializerError)

Hi everyone,

Well, i know that there’s another post with this problem, but, i didin’t find the solution and i have more clues of the problem.

I have my Android App, that i’m testing with two devices: a Nexus 7 (2013) with Marshmallow 6.0.1 and a Blu Advance 4.0 with JellyBean 4.2.2

Some clues that i’ve found:

    This error (java.lang.NoClassDefFoundError: weborb.types.Types) is only in the Blu device. It works like a charm in the Nexus 7. It's appears ONLY when i launch an activity of the app that's not the Main Activity, for example, a notification that have an intent to launch a secondary activity, or an UncaughtExceptionHandler with launch an activity that can send a report (.txt) to the Backendless servers. If the aplication runs from the MainActivity, works well.
Here's the Logcat of the error:

java.lang.NoClassDefFoundError: weborb.types.Types
	at com.backendless.UserService.<init>(UserService.java:56)
	at com.backendless.UserService.<clinit>(UserService.java:47)
	at com.backendless.Backendless.<clinit>(Backendless.java:44)
	at com.sdevelop.taxionline.MostrarError.enviarErrorAlServidor(MostrarError.java:64)
	at com.sdevelop.taxionline.MostrarError.access$100(MostrarError.java:30)
	at com.sdevelop.taxionline.MostrarError$2.onClick(MostrarError.java:57)
	at android.view.View.performClick(View.java:4212)
	at android.view.View$PerformClick.run(View.java:17476)
	at android.os.Handler.handleCallback(Handler.java:800)
	at android.os.Handler.dispatchMessage(Handler.java:100)
	at android.os.Looper.loop(Looper.java:194)
	at android.app.ActivityThread.main(ActivityThread.java:5371)
	at java.lang.reflect.Method.invokeNative(Native Method)
	at java.lang.reflect.Method.invoke(Method.java:525)
	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
	at dalvik.system.NativeStart.main(Native Method)

The error points always at the first line where there’s an instance of Backendless.

Things that i’ve tried:

    javaMaxHeapSize "4g" Update Android Studio to V2.0 and gradle to 2.0.0 Add -dontwarn -keep class weborb.** {*;} -keep class com.backendless.** {*;} in the proguard-rules.pro PENDING: Throw the device from the windows.
There's a solution?

EDIT: I try the app with another device (Sony Xperia E Android 4.1.1) and throws me a similar error:


java.lang.ExceptionInInitializerError
	at com.sdevelop.taxionline.MostrarError.enviarErrorAlServidor(MostrarError.java:62)
	at com.sdevelop.taxionline.MostrarError.access$100(MostrarError.java:30)
	at com.sdevelop.taxionline.MostrarError$2.onClick(MostrarError.java:55)
	at android.view.View.performClick(View.java:4106)
	at android.view.View$PerformClick.run(View.java:17150)
	at android.os.Handler.handleCallback(Handler.java:615)
	at android.os.Handler.dispatchMessage(Handler.java:92)
	at android.os.Looper.loop(Looper.java:137)
	at android.app.ActivityThread.main(ActivityThread.java:4793)
	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:808)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:575)
	at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.ExceptionInInitializerError
	at com.backendless.Backendless.<clinit>(Backendless.java:44)
	... 14 more
Caused by: java.lang.NoClassDefFoundError: weborb.types.Types
	at com.backendless.UserService.<init>(UserService.java:56)
	at com.backendless.UserService.<clinit>(UserService.java:47)
	... 15 more
java.lang.ExceptionInInitializerError
************ INFORMACION DEL DISPOSITIVO ***********
Brand: Sony
Device: C1504
Model: C1504
Product: C1504_1275-6551


************ FIRMWARE ************
SDK: 16
Release: 4.1.1


Hi Adan,

We noticed (and other users reported it too) that these errors occur when an app has multiple dependencies (other jars that is) and essentially runs out of the heap space. Unfortunately, this is outside of our control or anything we can do within our SDK.

What does your dependency list in gradle config look like?

Regards,
Mark

Hi Mark, thanks for your answer.

The dependency looks very ugly:

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile files('libs/backendless.jar')
    compile files('libs/butterknife-7.0.1.jar')
    compile 'com.android.support:appcompat-v7:23.2.1'
    compile 'com.google.android.gms:play-services:8.4.0'
    compile 'com.android.support:cardview-v7:23.2.1'
    compile 'com.android.support:recyclerview-v7:23.2.1'
    compile 'com.android.support:support-v4:23.2.1'
    compile 'com.android.support:design:23.2.1'
    compile 'com.android.support:multidex:1.0.0'} 

And i was thinking to add the facebook integration, but with this problem i can’t.

I hope there’s a solution :frowning:

Thanks for the help Mark! :smiley:

Yes, this is very consistent with what other developers reported. We were not able to find a solution. Getting it working on a simulator boils down to increasing available RAM for the virtual machine. As for the device itself, it is a hit or miss.

Yeah, it looks like the device doesn’t have the memory to load all the libraries to use, i’ll post this on the Group of Android Developers in Google +, if i find a solution i’ll post it here. I’ll also try to put a dispatch method in the MainActivity depending on the extras of the intent, it’s not the best practice but i think that could work momentaneously

Thank you very very much Mark for your help

You are welcome, Adan. Yes, please post anything you can find related to this subject.

Cheers,
Mark

Hey Mark, it’s like a miracle, i’ve found the solution.

First i look here: http://support.backendless.com/t/cannot-add-backendless-through-gradle_1

In this post i’ve got a link: http://stackoverflow.com/questions/27698287/noclassdeffounderror-with-android-studio-on-android-4

And the Solution is:

"To fix it, you have to do more than just set multiDexEnabled = true in your defaultConfigblock. You also have to:

    Include compile 'com.android.support:multidex:1.0.1' in your dependencies Have your Application class extend MultiDexApplication instead of just Application. Alternatively, you can call MultiDex.install() in attachBaseContext() of your application. "
I already did the step one, but i only add the MultiDex.install(this) in the attachBaseContext() (i didn't extends MultiDexApplication) and looks like this:

@Override
protected void attachBaseContext(Context base) {
super.attachBaseContext(base);
MultiDex.install(this);
}
And works like a charm.

Thank you very much Mark.

Great job, Adan! I’ll make sure we update the docs with that “recipe”.

WOW!!! It really works!! Thank you!!