0

I am learning android data binding in android. As per the tutorials available in the sites, I used below code (as per this site : https://www.androidauthority.com/data-binding-in-android-709747/) in build.gradle file android { compileSdkVersion 24 buildToolsVersion "24.0.0" dataBinding.enabled = true }

As I wrote this code in build.gradle file and hyperlink appeared in android studio sync now. Screenshot below. build.gradle screenshot

I clicked in the sync now hyperlink and it showed error in event log. Below is the error.

Gradle sync failed: Could not find method android() for arguments [build_a9l2u6i44dsxt8c6i2t9xn8sf$_run_closure1@44f18ebf] on root project 'TestDataBinding' of type org.gradle.api.Project. Consult IDE log for more details (Help | Show Log)

Please advice how to deal with this error and learn data binding in android.

I am using android studio 2.3.3

Mr Learner
  • 63
  • 9
  • you should have this in your apps build.gradle. See Module:app in your screen shot on the left. and read https://developer.android.com/topic/libraries/data-binding/index.html – Raghunandan Oct 15 '17 at 05:58
  • Edited build.gradle and placed below code android { dataBinding{ enabled = true } } It gives below error Gradle sync failed: Could not find method android() for arguments [build_a9l2u6i44dsxt8c6i2t9xn8sf$_run_closure1@cc88904] on root project 'TestDataBinding' of type org.gradle.api.Project. Consult IDE log for more details (Help | Show Log) – Mr Learner Oct 15 '17 at 06:46
  • where did you place the lines. Can you post your both build.gradle files code – Raghunandan Oct 15 '17 at 06:47
  • Thanks @Raghunandan. As you have said "Can you post your both build.gradle files code", I started looking into the gradle files. I was editing "build.gradle (Project: testDataBinding)". I removed the lines from that file and inserted below code in "bild.gradle (Module: app)" dataBinding{ enabled=true } After inserting these lines I clicked on sync now and all errors gone away. Thanks a lot for the hint :) Again one question is coming into my mind. Why there are two gradles? What are their functionalities. – Mr Learner Oct 15 '17 at 07:09
  • have a look here https://stackoverflow.com/questions/28295933/difference-between-build-gradleproject-and-build-gradlemodule – Raghunandan Oct 15 '17 at 12:30

0 Answers0