BR无法解决

时间:2015-12-04 12:44:25

标签: android android-studio data-binding android-gradle build.gradle

由于gradle中存在某些问题,我无法添加notifyPropertyChanged(int itemId),我猜!

任何帮助都会受到赞赏

public class RegisterForm extends BaseObservable {
    @Bindable
    public String firstName;


    @Bindable
    public int getFirstNameLabelVisibility(){
        return TextUtils.isEmpty(firstName) ? View.INVISIBLE : View.VISIBLE;
    }

    public void setFirstNameFromView(String firstNameFromView) {
        firstName = firstNameFromView;

//        notifyPropertyChanged(BR.firstName); this line is giving error!
    }


}

Build.gradle // for App

apply plugin: 'com.android.application'
apply plugin: 'com.android.databinding'
apply plugin: 'android-apt'
android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    defaultConfig {
        applicationId "com.example.jivrajsingh.databindingimp"
        minSdkVersion 15
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }
}
configurations {
    apt
}
dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    testCompile 'junit:junit:4.12'
    apt 'com.android.databinding:compiler:1.0-rc0'
    compile 'com.android.support:appcompat-v7:23.1.1'
    compile 'com.squareup.okhttp:okhttp:2.4.0'
    compile 'com.google.android.gms:play-services-auth:8.3.0'
    compile 'com.google.android.gms:play-services-gcm:8.3.0'
}

Build.gradle // for project

// Top-level build file where you can add configuration options common to all sub-projects/modules.



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

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
      //  classpath 'com.android.tools.build:gradle:1.3.0'
        classpath 'com.android.databinding:dataBinder:1.0-rc2'
        classpath 'com.neenbedankt.gradle.plugins:android-apt:1.+'
    }
}

allprojects {
    repositories {
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

感谢您宝贵的时间:)

1 个答案:

答案 0 :(得分:2)

您使用新的gradle版本设置旧插件。 删除数据绑定插件&它与classpath的依赖关系。 现在它已集成,您只需要

android {
   dataBinding { enabled = true }
}

http://developer.android.com/tools/data-binding/guide.html

相关问题