Moving your Android Data Binding app out of beta

At Google I/O 2015, the Android Data Binding library was introduced. The Data Binding Library as put out in the Guide, gives you the opportunity to write declarative layouts and minimize the glue code necessary to bind your application logic and layouts. Many people have argued that this will give developers the power to write business logic in XML, which some developers are trying to move away from altogether.

So I jumped on the Data Binding bandwagon and eventually shipped an Android app into production with Data Binding (really?! yes — I swallowed the Data Binding “beta” pill).

The app has been running smoothly in production with no issue. I recently went back to my app to make some changes but Android studio kept complaining about my plugin being too old, so I tasked Android studio to fix it and these happened after the fix.

Error:Unable to find method ‘android.databinding.tool.LayoutXmlProcessor.<init>(Ljava/lang/String;Landroid/databinding/tool/writer/JavaFileWriter;IZLandroid/databinding/tool/LayoutXmlProcessor$OriginalFileLookup;)V’.
Possible causes for this unexpected error include:<ul><li>Gradle’s dependency cache may be corrupt (this sometimes occurs after a network connection timeout.)
<a href=”syncProject”>Re-download dependencies and sync project (requires network)</a></li><li>The state of a Gradle build process (daemon) may be corrupt. Stopping all Gradle daemons may solve this problem.
<a href=”stopGradleDaemons”>Stop Gradle build processes (requires restart)</a></li><li>Your project may be using a third-party plugin which is not compatible with the other plugins in the project or the version of Gradle requested by the project.</li></ul>In the case of corrupt Gradle processes, you can also try closing the IDE and then killing all Java processes.

Turns out The Data Binding Library has moved on and I’m still stuck in beta.

During the beta days of the Data Binding Library, you had to add the following dependencies to your classpath in the top level build.gradle file.

dependencies {
classpath "com.android.tools.build:gradle:{1.3.0-beta4 - 1.4.0-beta6}"
classpath "com.android.databinding:dataBinder:{1.0-rc[0..4]}"
}

The Data Binding plugin must then be applied to your app module’s build.gradle file after the application plugin.

apply plugin: 'com.android.application'
apply plugin: 'com.android.databinding'

Turns out The Data Binding Library is no longer in beta and the only thing that must be done to start enjoying all the Data Binding goodness is to just add the dataBinding element to your build.gradle file in the app module.

android {
....
dataBinding {
enabled = true
}
}

Conclusion

During the time of writing my app the Data Binding Library did not support two-way data binding so I rolled out my own solution. But Android plugin 2.1 alpha 3 now contains official two way data binding support. Watch out for my sequel on how I replaced my custom two-way data binding solution with the official version.