Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I'm not able to setup Android Data Binding

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.

like image 305
Héctor Avatar asked Aug 09 '26 12:08

Héctor


1 Answers

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

like image 59
IntelliJ Amiya Avatar answered Aug 12 '26 01:08

IntelliJ Amiya



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!