更改文件名后未解决的数据绑定

时间:2018-02-14 12:35:47

标签: android kotlin

我在AndroidKotlin应用中更改了全局替换的类名。之后它会为新名称显示UnresolvedDataBinding。所以我把AName更改为BName 在任何地方都找不到FragmentBName数据绑定。我查了一下

   dataBinding {
    enabled = true
   }

为什么只更改文件名清理和重建不能重新生成Bindings?

这是通过gradle.build for module

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'

android {
    compileSdkVersion rootProject.ext.compileSdkVersion
    buildToolsVersion rootProject.ext.buildToolsVersion
    flavorDimensions "default"

    defaultConfig {
        applicationId "com.example.android.architecture.blueprints.todomvvmlive"
        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner'
    }

    buildTypes {
        debug {
            //TODO fix minify for HolderFragment
            minifyEnabled false
            // Uses new built-in shrinker http://tools.android.com/tech-docs/new-build-system/built-in-shrinker
            useProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            testProguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguardTest-rules.pro'
        }

        release {
            minifyEnabled true
            useProguard true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            testProguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguardTest-rules.pro'
        }
    }

    // If you need to add more flavors, consider using flavor dimensions.
    productFlavors {
        mock {
            applicationIdSuffix = ".mock"
        }
        prod
    }

    // Remove mockRelease as it's not needed.
    android.variantFilter { variant ->
        if(variant.buildType.name.equals('release')
                && variant.getFlavors().get(0).name.equals('mock')) {
            variant.setIgnore(true);
        }
    }

    // Always show the result of every unit test, even if it passes.
    testOptions.unitTests.all {
        testLogging {
            events 'passed', 'skipped', 'failed', 'standardOut', 'standardError'
        }
    }

    dataBinding {
        enabled = true
    }
    buildToolsVersion '26.0.2'
}

/*
 Dependency versions are defined in the top level build.gradle file. This helps keeping track of
 all versions in a single place. This improves readability and helps managing project complexity.
 */
dependencies {
    // App's dependencies, including test
    compile "com.android.support:appcompat-v7:$rootProject.supportLibraryVersion"
    compile "com.android.support:cardview-v7:$rootProject.supportLibraryVersion"
    compile "com.android.support:design:$rootProject.supportLibraryVersion"
    compile "com.android.support:recyclerview-v7:$rootProject.supportLibraryVersion"
    compile "com.android.support:support-v4:$rootProject.supportLibraryVersion"
    compile "com.android.support.test.espresso:espresso-idling-resource:$rootProject.espressoVersion"
    compile "com.google.guava:guava:$rootProject.guavaVersion"

    compile "android.arch.lifecycle:extensions:$rootProject.archLifecycleVersion"
    annotationProcessor "android.arch.lifecycle:compiler:$rootProject.archLifecycleVersion"
    kapt "com.android.databinding:compiler:4.1"
   // kapt 'com.android.databinding:compiler:2.3.1'

    // Dependencies for local unit tests
//    testCompile "junit:junit:$rootProject.ext.junitVersion"
//    testCompile "org.mockito:mockito-all:$rootProject.ext.mockitoVersion"
//    testCompile "org.hamcrest:hamcrest-all:$rootProject.ext.hamcrestVersion"
//
//    testCompile "android.arch.core:core-testing:$rootProject.archLifecycleVersion"

    // Android Testing Support Library's runner and rules
//    androidTestCompile "com.android.support.test:runner:$rootProject.ext.runnerVersion"
//    androidTestCompile "com.android.support.test:rules:$rootProject.ext.runnerVersion"

    // Dependencies for Android unit tests
//    androidTestCompile "junit:junit:$rootProject.ext.junitVersion"
//    androidTestCompile "org.mockito:mockito-core:$rootProject.ext.mockitoVersion"
//    androidTestCompile 'com.google.dexmaker:dexmaker:1.2'
//    androidTestCompile 'com.google.dexmaker:dexmaker-mockito:1.2'

    // Espresso UI Testing
//    androidTestCompile "com.android.support.test.espresso:espresso-core:$rootProject.espressoVersion"
//    androidTestCompile "com.android.support.test.espresso:espresso-contrib:$rootProject.espressoVersion"
//    androidTestCompile "com.android.support.test.espresso:espresso-intents:$rootProject.espressoVersion"

    // Resolve conflicts between main and test APK:
//    androidTestCompile "com.android.support:support-annotations:$rootProject.supportLibraryVersion"
//    androidTestCompile "com.android.support:support-v4:$rootProject.supportLibraryVersion"
//    androidTestCompile "com.android.support:recyclerview-v7:$rootProject.supportLibraryVersion"
//    androidTestCompile "com.android.support:appcompat-v7:$rootProject.supportLibraryVersion"
//    androidTestCompile "com.android.support:support-compat:$rootProject.supportLibraryVersion"
//    androidTestCompile "com.android.support:design:$rootProject.supportLibraryVersion"
    compile "com.google.code.findbugs:jsr305:2.0.1"
    compile "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
}
repositories {
    mavenCentral()
}

1 个答案:

答案 0 :(得分:0)

您还应将此添加到build.gradle

apply plugin: 'kotlin-kapt'

kapt "com.android.databinding:compiler:$gradle_version"