Algolia Community

Getting java.lang.NoClassDefFoundError for DataBinderMapperImpl

instantsearch

#1

I am following Getting Started for InstantSearch for Android.
Getting following error in the Activity containing the InstantSearch codes:

java.lang.NoClassDefFoundError: Failed resolution of: Lcom/android/databinding/library/baseAdapters/DataBinderMapperImpl;

I have enabled the dataBinging in build gradle file.
The app is crashing as soon as the activity is displayed.
Java and XML files contain the same code as written in the documentation.

Kindly tell me if you need any specific code or more info.

I am pasting here the error logs:

--------- beginning of crash
2018-11-09 22:34:00.421 26021-26021/ecelladgitm.com.data E/AndroidRuntime: FATAL EXCEPTION: main
Process: ecelladgitm.com.data, PID: 26021
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/android/databinding/library/baseAdapters/DataBinderMapperImpl;
    at com.algolia.instantsearch.DataBinderMapperImpl.collectDependencies(DataBinderMapperImpl.java:71)
    at androidx.databinding.MergedDataBinderMapper.addMapper(MergedDataBinderMapper.java:58)
    at androidx.databinding.MergedDataBinderMapper.addMapper(MergedDataBinderMapper.java:60)
    at androidx.databinding.DataBinderMapperImpl.<init>(DataBinderMapperImpl.java:5)
    at androidx.databinding.DataBindingUtil.<clinit>(DataBindingUtil.java:32)
    at androidx.databinding.DataBindingUtil.inflate(DataBindingUtil.java:95)
    at com.algolia.instantsearch.ui.views.Hits$HitsAdapter.onCreateViewHolder(Hits.java:459)
    at com.algolia.instantsearch.ui.views.Hits$HitsAdapter.onCreateViewHolder(Hits.java:424)
    at androidx.recyclerview.widget.RecyclerView$Adapter.createViewHolder(RecyclerView.java:6794)
    at androidx.recyclerview.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:5975)
    at androidx.recyclerview.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5858)
    at androidx.recyclerview.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:5854)
    at androidx.recyclerview.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:2230)
    at androidx.recyclerview.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1557)
    at androidx.recyclerview.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1517)
    at androidx.recyclerview.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:612)
    at androidx.recyclerview.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:3924)
    at androidx.recyclerview.widget.RecyclerView.onMeasure(RecyclerView.java:3336)
    at android.view.View.measure(View.java:19886)
    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6085)
    at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1464)
    at android.widget.LinearLayout.measureVertical(LinearLayout.java:758)
    at android.widget.LinearLayout.onMeasure(LinearLayout.java:640)
    at android.view.View.measure(View.java:19886)
    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6085)
    at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
    at androidx.appcompat.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:143)
    at android.view.View.measure(View.java:19886)
    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6085)
    at androidx.appcompat.widget.ActionBarOverlayLayout.onMeasure(ActionBarOverlayLayout.java:401)
    at android.view.View.measure(View.java:19886)
    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6085)
    at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
    at android.view.View.measure(View.java:19886)
    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6085)
    at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1464)
    at android.widget.LinearLayout.measureVertical(LinearLayout.java:758)
    at android.widget.LinearLayout.onMeasure(LinearLayout.java:640)
    at android.view.View.measure(View.java:19886)
    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6085)
    at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
    at com.android.internal.policy.DecorView.onMeasure(DecorView.java:693)
    at android.view.View.measure(View.java:19886)
    at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2319)
    at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1410)
    at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1663)
    at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1298)
    at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6437)
    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:876)
    at android.view.Choreographer.doCallbacks(Choreographer.java:688)
2018-11-09 22:34:00.423 26021-26021/ecelladgitm.com.data E/AndroidRuntime:     at android.view.Choreographer.doFrame(Choreographer.java:623)
    at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:862)
    at android.os.Handler.handleCallback(Handler.java:754)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:163)
    at android.app.ActivityThread.main(ActivityThread.java:6238)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:933)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:823)
 Caused by: java.lang.ClassNotFoundException: Didn't find class "com.android.databinding.library.baseAdapters.DataBinderMapperImpl" on path: DexPathList[[zip file "/data/app/ecelladgitm.com.data-1/base.apk", zip file "/data/app/ecelladgitm.com.data-1/split_lib_dependencies_apk.apk", zip file "/data/app/ecelladgitm.com.data-1/split_lib_slice_0_apk.apk", zip file "/data/app/ecelladgitm.com.data-1/split_lib_slice_1_apk.apk", zip file "/data/app/ecelladgitm.com.data-1/split_lib_slice_2_apk.apk", zip file "/data/app/ecelladgitm.com.data-1/split_lib_slice_3_apk.apk", zip file "/data/app/ecelladgitm.com.data-1/split_lib_slice_4_apk.apk", zip file "/data/app/ecelladgitm.com.data-1/split_lib_slice_5_apk.apk", zip file "/data/app/ecelladgitm.com.data-1/split_lib_slice_6_apk.apk", zip file "/data/app/ecelladgitm.com.data-1/split_lib_slice_7_apk.apk", zip file "/data/app/ecelladgitm.com.data-1/split_lib_slice_8_apk.apk", zip file "/data/app/ecelladgitm.com.data-1/split_lib_slice_9_apk.apk"],nativeLibraryDirectories=[/data/app/ecelladgitm.com.data-1/lib/arm64, /system/lib64, /vendor/lib64]]
    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:380)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
    	... 59 more

Gap between two rows when keyboard is hidden
#2

Hi there, thanks for reaching out and sorry for the inconvenience!

(First of all, let’s get this out of the way: I’ll assume you did turn on dataBinding.enabled true in your build.gradle's android closure to enable Data Binding.)

The issue you share was just reported by a user developing an app with AndroidX, which makes me wonder if you are in the same situation. ​
Could you share your app’s build.gradle so that I can compare the dependencies you use?​​

I guess the issue happens in development builds as well ; should it not be the case, can you share as well your Proguard file ​​if you have one?

I’m currently working on this AndroidX compatibility issue, hopefully your situation is related and will be resolved along! Else I’ll investigate independently.


#3

@pln
Here’s my build.gradle file

apply plugin: 'com.android.application'
apply plugin: 'com.google.gms.google-services'

android {
    compileSdkVersion 28
    dataBinding {
        enabled = true
    }

    defaultConfig {
        applicationId "ecelladgitm.com.data"
        minSdkVersion 21
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.0.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test:runner:1.1.0'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0'
    implementation 'com.google.firebase:firebase-database:16.0.4'
    implementation 'com.google.firebase:firebase-firestore:17.1.2'

    implementation 'com.algolia:algoliasearch-android:3.+'
    implementation 'com.algolia:instantsearch-android:1.13.0'

    implementation('com.google.api-client:google-api-client-android:1.25.0') {
        exclude group: 'org.apache.httpcomponents'
    }
    implementation('com.google.apis:google-api-services-youtube:v3-rev206-1.25.0') {
        exclude group: 'org.apache.httpcomponents'
    }
    implementation 'androidx.cardview:cardview:1.0.0'
}

Currently, I am testing the app in development mode so I am not using proguard but let me know if I have to modify the proguard file when I will be using it. My proguard file is empty currently.


#4

Hi pln.

Just got this exception myself, and it is, without a doubt, because of androidX.

I wanted to hear, if you have an ETA on a fix for this, or if I should just go ahead, and go back to com.support libraries?


#5

Hi @casper, thanks for your report and sorry for the troubles caused by this situation.

From my investigation, the current library should work with AndroidX applications.
The Jetifier tool’s description states that it “migrates support-library-dependent libraries to rely on the equivalent AndroidX packages instead”, meaning that using Migrate to AndroidX in Android Studio should be all you need to use InstantSearch Android with an AndroidX-enabled app.

(Note that the tool only works with android.enableJetifier=true and android.useAndroidX=true. I assume you followed the Migration Guide and added those to your gradle.properties.)


From both @sub.vivekkumar69’s and your account, it is not the case. I replicated the situation with a simple application using AndroidX and a library using android.support, indeed the same NoClassDefFoundError: Failed resolution of: Lcom/android/databinding/library/baseAdapters/DataBinderMapperImpl arises.

I filed a report for this bug on Google’s bug tracker. Can you star it to help Google prioritize it higher?


Regarding ETA/fix for this, it seems we have two options:

  • Stick to the current implementation, requiring InstantSearch apps to keep using android.support libraries until the bug is fixed by Google or we find a workaround
  • Release a new version of InstantSearch based on AndroidX, which won’t be usable by apps that have not migrated yet. This would mean maintaining two versions of our library until the situation is resolved.

I’ll discuss both options with our team and come back to you. I myself believe we need to support AndroidX as soon as possible, so am leaning towards the second option, but will share thoughts with our broader mobile team before taking a decision. I’ll keep you updated here as soon as possible, which should be tomorrow or the following days!


#6

Hi @pln, thank you for a quick reply.

I can confirm I have jetifier enabled, so it would seem like it’s a problem within jetifier.
I have starred the bug on the tracker.

Not sure if it’s relevant information, but I’m using databinding from androidX elsewhere in my project, and implementing instant-search in my dependencies, causes that databinding to fail (with the NoClassDefFoundError exception), which I find quite odd, to be completely honest.


#7

@pln
Any update/progress?


#8

Hi @casper and @sub.vivekkumar69,

Not sure if it’s relevant information, but I’m using databinding from androidX elsewhere in my project, and implementing instant-search in my dependencies, causes that databinding to fail (with the NoClassDefFoundError exception), which I find quite odd, to be completely honest.

It makes sense, using androidx.databinding works in AndroidX-based apps, but using our library which leverages android.support.databinding causes the error due to the linked bug.

Any update/progress?

We are about to release a new artifact refactored with androidX to unblock you until the bug is resolved. To avoid forcing our other customers to update, we’ll likely keep instantsearch-android on support.v7 while releasing a new instantsearch-androidx based on AndroidX that you’ll be able to use in your projects.

This situation with two different artifacts will be temporary, and will resolve as soon as:

  • Google fixes the jetifier issue, allowing us to ship the initial support.v7 codebase for both support.v7 users and AndroidX users like you
  • AndroidX becomes the norm and we can drop support of support.v7 package

When either happens, we’ll delete the instantsearch-androidx artifacts and will be back to simply exposing instantsearch-android.


#9

Thanks and I appreciate your efforts. :slightly_smiling_face:


#10

Great news!

Would you please post on this thread, when this new AndroidX artifact is released?


#11

@Casper I will! Currently the package is waiting to be accepted into JCenter.


#12

Update

Just for fun, I tried to look for instantsearch-androidx on JCenter, and it was there.
I tried implementing it, and it is working!

Thank you for the quick (albeit temporary) fix for this problem @pln!


#13

Hi @casper, haha I didn’t expect you to pick it up before I announce it :upside_down_face:
very good]
Thanks for the positive feedback, I hope this fix won’t be needed for a long time :slight_smile:


#14

@sub.vivekkumar69 and other readers, our InstantSearch AndroidX artifacts are now available!
You can use these within your AndroidX Application as long as the Jetifier <> Android.Databinding bug is unsolved.

To use the AndroidX version of our library, you shall use these artifacts:

implementation 'com.algolia:instantsearch-androidx:1.14.0' // Full library
// OR INSTEAD
implementation 'com.algolia:instantsearch-androidx-core:1.14.0' // Core library (no Widgets/databinding logic)

You can check the androidX branch of our instantsearch-android-mvp project, which follows this logic to build with InstantSearch and AndroidX.

Updates will be released there as well as on the original instantsearch-android artifacts until the situation is resolved and we can get back to a single line of artifacts!