3

I have this in my root build.gradle file:

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:1.5.0'
    }
}

and in the app build.gradle file:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 21
    buildToolsVersion "23.0.1"

    defaultConfig {
        applicationId "com.company.app"
        minSdkVersion 14
        targetSdkVersion 21
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:22.2.0'
    //more third-party libraries
}

And this is my layout:

<layout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools">

    <data>

        <variable
            name="user"
            type="com.company.app.models.LoginCredentials"/>
    </data>

    <EditText
        android:layout_width="match_parent"
        android:layout_height="55dp"
        android:text="@{user.username}"/>

    <!-- More layouts and widgets -->
</layout>

But I get this error:

Error:(82, 35) No resource type specified (at 'text' with value '@{user.username}').

I have tried to put:

dataBinding { 
    enabled = true 
}

but I get this another error:

Error:Could not find com.android.databinding:library:1.0-rc3.

How can I do? I have just updated Android Studio to v1.5.1.

5
  • 3
    At first set compileSdkVersion 23 buildToolsVersion "23.0.1" & targetSdkVersion 23 & compile 'com.android.support:appcompat-v7:23.1.0' Commented Jan 14, 2016 at 8:09
  • 2
    as @IntelliJAmiya says change version 21 to 23 Commented Jan 14, 2016 at 8:18
  • 1
    And don't forget dataBinding{ enabled = true }in the android { } section. Commented Jan 14, 2016 at 8:25
  • 1
    At least it works!! Thanks! I have put dataBinding.enabled = true and updated version to 23 Commented Jan 14, 2016 at 8:44
  • 1
    @bigdestroyer Glad to hear . Commented Jan 14, 2016 at 8:51

2 Answers 2

2

Actually compileSdkVersion 21 creating problem . You need to use UPGRADED Version .

You should use

compileSdkVersion 23 
buildToolsVersion "23.0.1" 

&

targetSdkVersion 23  

You need to include dataBinding.enabled = true

Sign up to request clarification or add additional context in comments.

Comments

0
  1. Add classpath "com.android.databinding:dataBinder:1.0-rc1" to your build.gradle like this

    buildscript { repositories { jcenter() } dependencies { classpath 'com.android.tools.build:gradle:1.5.0' classpath "com.android.databinding:dataBinder:1.0-rc1" } }

  2. Change your build.gradle on putting what as mentioned in the previous comments of @IntelliJAmiya and adding apply plugin: 'com.android.databinding' Your gradle will be like

    apply plugin: 'com.android.application'
    apply plugin: 'com.android.databinding'  
     android {
        compileSdkVersion 23
        buildToolsVersion "23.0.1"
    
    
      defaultConfig {
            applicationId "com.company.app"
            minSdkVersion 14
            targetSdkVersion 21
            versionCode 1
            versionName "1.0"
        }
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android.txt'),   'proguard-rules.pro'
            }
        }
    }
     dataBinding { 
            enabled = true 
        }
        dependencies {
            compile fileTree(dir: 'libs', include: ['*.jar'])
            testCompile 'junit:junit:4.12'
            compile 'com.android.support:appcompat-v7:23.1.0'
            //more third-party libraries
        }
    `
    

1 Comment

Thanks for your answer. Actually, com.android.databinding:dataBinder:1.0-rc1 is not needed to be declared explicitly. It is included in classpath 'com.android.tools.build:gradle:1.5.0'.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.