java.lang.NoClassDefFoundError: Failed resolution of: Lcom/package/id/MyLayoutBinding

Ravi Bhojwani
2 min readMay 31, 2018

--

Sometime back we upgraded our android project gradle wrapper version from 4.1 to 4.3. App consumed a library which was using android data binding library to bind UI components in layouts to data sources.

Few days passed and all of a sudden we started seeing crash w.r.t library using data binding as below:

java.lang.NoClassDefFoundError: Failed resolution of: Lcom/package/id/databinding/MyLayoutBinding;
at com.package.id.a.onCreateDialog(MyFragment.java:77)
at android.app.DialogFragment.onGetLayoutInflater(DialogFragment.java:406)
at android.app.Fragment.performGetLayoutInflater(Fragment.java:1325)

.

.

Caused by: java.lang.ClassNotFoundException: Didn’t find class “com.package.id.databinding.MyLayoutBinding” on path: DexPathList

We went clueless on what’s happening. There was no change in library code and it got difficult to identify what caused this regression. Finally after lot of reverse engineering and trying out previous builds we found that it was gradle upgrade which blowed up app. Ideally this could have been caught in dev phase while gradle was upgraded but as the library code gets executed on particular condition which happens once in 2–3 week and hence it remained uncaught.

Now what’s the fix? It was hard to find the solution for this over web. Spent almost 2–3 days and found following solution that worked for me and thats the intention behind this post to save time for developers facing same issue.

Changes in bold in each section are the ones that helped fix it.

build.gradle

defaultConfig {multiDexEnabled = true
multiDexKeepProguard file(‘multi-dex-keep.txt’)

}

dataBinding { version ‘2.3.0’
enabled true
}

gradle.properties

android.databinding.enableV2=false

multi-dex-keep.txt (added this file with below text)

-keep public class * extends android.databinding.ViewDataBinding {
*;
}

This may not be the right solution , but this helped me fix the issue.

While later we realised that the issue was with gradle 4.3. With gradle 4.4 everything is working fine. So to make right fix, we are in process of upgrading app and all referenced libs to 4.4.

Hope this post helps someone.

--

--