3

I recently updated Android Studio to 2.3, as well as gradle to 2.3.0. Since the last time my application was working properly, I've made no other changes, but now whenever executing this line of code:

ViewDataBinding viewDataBinding = DataBindingUtil.setContentView(this,R.layout.main_activity);

I get this error:

java.lang.NoClassDefFoundError: android.databinding.DataBinderMapper
     at android.databinding.DataBindingUtil.<clinit>(DataBindingUtil.java:31)
     at com.app.MainActivity.onCreate(MainActivitiy.java:108)
     at android.app.Activity.performCreate(Activity.java:5426)
     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2269)
     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2363)
     at android.app.ActivityThread.access$900(ActivityThread.java:161)
     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1265)
     at android.os.Handler.dispatchMessage(Handler.java:102)
     at android.os.Looper.loop(Looper.java:157)
     at android.app.ActivityThread.main(ActivityThread.java:5356)
     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:1265)
     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
     at dalvik.system.NativeStart.main(Native Method)

According to this SO answer, gradle dependencies that are including support-v4 r21 is a problem. It turns out that my dependencies include that, but not because of a dependency that I added, but because I added:

dataBinding {
    enabled = true
}

Because of this, I see that these dependencies are added to my project:

+--- com.android.databinding:library:1.3.1
|    +--- com.android.support:support-v4:21.0.3 -> 24.0.0 (*)
|    \--- com.android.databinding:baseLibrary:2.3.0-dev -> 2.3.0
+--- com.android.databinding:baseLibrary:2.3.0
\--- com.android.databinding:adapters:1.3.1
     +--- com.android.databinding:library:1.3 -> 1.3.1 (*)
     \--- com.android.databinding:baseLibrary:2.3.0-dev -> 2.3.0

And as you can see, com.android.databinding:library:1.3.1 includes support-v4:21.0.3.

This is my full module build.gradle file:

apply plugin: 'com.android.application'
apply plugin: 'realm-android'

android {
    compileSdkVersion 23
    buildToolsVersion '25.0.0'
    defaultConfig {
        applicationId "com.app"
        minSdkVersion 16
        targetSdkVersion 23
        versionCode 12
        versionName "0.2.1"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        debug {
            debuggable true
        }
    }
    dataBinding {
        enabled = true
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:23.2.1'
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:support-v4:23.2.1'
    compile 'com.android.support:recyclerview-v7:23.2.1'
    compile 'com.android.volley:volley:1.0.0'
    compile 'io.realm:android-adapters:1.3.0'
    compile 'joda-time:joda-time:2.9.4'
    compile 'com.android.volley:volley:1.0.0'
    compile 'com.google.code.gson:gson:2.6.2'
    compile 'com.google.android.gms:play-services-ads:9.8.0'
}

Any idea how I can fix this issue?

Community
  • 1
  • 1
shoe
  • 952
  • 1
  • 20
  • 44
  • I also faced many issues after upgrading studio to 2.3 try to use build tool version and support library version same. this may be resolved your issue iam not sure but in my case it works – Varun Jain Mar 07 '17 at 20:10
  • @VarunJain did it, but it didn't work for me – shoe Mar 07 '17 at 20:32
  • Yaa i can understand the pain bro 2 days back i also suffer this but some support library still of different version ...need to check the full tree of libraray – Varun Jain Mar 07 '17 at 20:34
  • another user had the same problem a couple years back, and [one of the solutions](http://stackoverflow.com/a/33007515/6744473) suggested including the `android-apt` plugin to fix it, but it turns out that android studio 2.3 no longer supports `android-apt` – shoe Mar 07 '17 at 20:37

0 Answers0