【问题标题】:BR cannot be resolvedBR 无法解决
【发布时间】:2016-03-09 09:49:01
【问题描述】:

我猜由于 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 // 用于应用程序

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 // 用于项目

// 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
}

感谢您宝贵的时间:)

【问题讨论】:

  • 为什么两者都有? classpath 'com.android.tools.build:gradle:2.0.0-alpha1'classpath 'com.android.tools.build:gradle:1.3.0' 还在哪里启用 App 的 gradle 中的 dataBinding? ...您是否阅读了“数据绑定指南”?
  • 那是注释代码 (gradle:1.3.0).. 早些时候我有它然后我把它改成 2.0
  • 我也在这里编辑...还有什么吗??
  • 是的,阅读指南...启用 dataBinding 仍然缺失...
  • Adding databinding{ enabled true} 仍然给我错误,但后来我意识到 apt 应该是 apt{} ,这样我就解决了问题,这是正确的吗?虽然我现在可以导入 *.BR 谢谢你的时间 :)

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


【解决方案1】:

你有旧的插件设置和新的 gradle 版本。 从类路径中删除数据绑定插件及其依赖项。 现在它已集成,您所需要的只是

android {
   dataBinding { enabled = true }
}

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

【讨论】:

    猜你喜欢
    • 2019-11-20
    • 1970-01-01
    • 2011-11-03
    • 2014-05-05
    • 2018-06-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-11
    • 1970-01-01
    相关资源
    最近更新 更多