0

My app was working.

I updated all my play services to 9.0.0, applied the 'com.google.gms.google-services' plugin, and the 'com.google.gms:google-services:3.0.0' classpath.

Now my app is crashing and throwing this error:

/UncaughtException: java.lang.NoClassDefFoundError: Failed resolution of: Lcom/fasterxml/jackson/databind/ObjectMapper;
    at com.firebase.client.core.view.QueryParams.<clinit>(QueryParams.java:36)
    at com.firebase.client.Firebase.<init>(Firebase.java:172)
    at com.firebase.client.Firebase.<init>(Firebase.java:177)
    at com.firebase.client.Firebase.<init>(Firebase.java:155)
    at com.defaultPackage.Application.addListener(Application.java:324)
    at com.defaultPackage.Application.onCreate(Application.java:84)
    at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1012)
    at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4553)
    at android.app.ActivityThread.access$1500(ActivityThread.java:151)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1364)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:135)
    at android.app.ActivityThread.main(ActivityThread.java:5254)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
 Caused by: java.lang.ClassNotFoundException: Didn't find class "com.fasterxml.jackson.databind.ObjectMapper" on path: DexPathList[[zip file "/data/app/com.defaultPackage-2/base.apk"],nativeLibraryDirectories=[/data/app/com.defaultPackage-2/lib/arm, /vendor/lib, /system/lib]]

I saw this question but the answer provided there did not solve the error for me.

Does anyone know what is causing it?

Community
  • 1
  • 1
Micah Simmons
  • 2,078
  • 2
  • 20
  • 38
  • 1
    What version of the Firebase Android SDK are you using? Can you share all of your dependencies? Firebase SDK 9.0.0 no longer depends on Jackson so if you're using the new SDK properly you should not see any references to Jackson classes. – Sam Stern May 21 '16 at 23:57
  • 1
    That sounds like the start of a good answer @hatboysam :-) – Frank van Puffelen May 22 '16 at 00:29
  • @FrankvanPuffelen In the end I found out this error was being thrown because of the way I had set up different productFlavours in my app level build.gradle. I've detailed what I did to stop the error being thrown in my answer – Micah Simmons May 22 '16 at 23:01

2 Answers2

3

The error mentions the Jackson ObjectMapper. The new Firebase Database Android SDK does not depend on Jackson at all, so your error implies that you are using some version of 'com.firebase:firebase-client-android'.

You should remove that library from your build.gradle. The library you want to use is: com.google.firebase:firebase-database:9.0.0

The migration guide explains the code changes needed to make this change. The most important change is the following:

BEFORE

Firebase ref = new Firebase("<URL>");

AFTER

DatabaseReference ref = FirebaseDatabase.getInstance.getReference();
Sam Stern
  • 24,624
  • 13
  • 93
  • 124
  • Thanks for your response. Stopping calls to the old Firebase object stops this error occuring, but is it not possible to have the new Firebase SDKs installed and continue to run the old Firebase SDK code at the same time? In the migration guide [here](https://firebase.google.com/support/guides/firebase-android#import_your_project_to_the_new_firebase_console_numbered) it does not say in the 'Install the new Firebase SDK' section that the old Firebase code will not work upon installing the new SDK – Micah Simmons May 22 '16 at 10:56
  • It is possible to have your old code running, however I would avoid doing a partial migration. If you are using any of the new `9.0.0` libraries I would update all components at once to avoid errors. Your old code, if you leave it 100% unmodified, should continue to run. – Sam Stern May 22 '16 at 18:54
  • Thanks for your response, but, in my case leaving the code 100% unmodified didn't allow the old Firebase code to run without throwing the java.lang.NoClassDefFoundError: error. I found out why this error was being thrown though, and I've provided the answer below – Micah Simmons May 22 '16 at 22:54
0

Update:

My original answer can solve the issue, but upon upgrading to the new Firebase SDK I was required to apply the plugin 'com.google.gms.google-services' but as I was already compiling 'com.google.android.gms:play-services:version' this caused some kind of conflict, and by removing the compiled play-services library from my app build.gradle the issue was fixed and my productFlavours no-longer needed to be removed

Original answer:

Leaving the Firebase SDK code 100% unmodified will in some cases let the old Firebase SDK function as it used to when you update to the new Firebase SDK. But, in my case despite leaving my code 100% the same as it was the java.lang.NoClassDefFoundError was being thrown.

The issue was caused by applying the line 'apply plugin: 'com.google.gms.google-services' to my app level build.gradle, the line 'classpath 'com.google.gms:google-services:3.0.0' to my project level build.gradle and the google-services file to the project and updating to google play services to 9.0.0

The update caused the java.lang.NoClassDefFoundError to be thrown by the Facebook Rebound library as well as the old Firebase SDK.

My project is a multidex project and in my app level build.gradle I had the lines:

 productFlavors {
        // Define separate dev and prod product flavors.
        dev {
            // dev utilizes minSDKVersion = 21 to allow the Android gradle plugin
            // to pre-dex each module and produce an APK that can be tested on
            // Android Lollipop without time consuming dex merging processes.
            minSdkVersion 21
        }
        prod {
            // The actual minSdkVersion for the application.
            minSdkVersion 14
        }
    }

By commenting out or removing these lines the java.lang.NoClassDefFoundError was no longer thrown by the old Firebase SDK or the Facebook Rebound library.

Micah Simmons
  • 2,078
  • 2
  • 20
  • 38