Android Studio 3.0 Databinding reference code not genereted by android studio

Viewed 1225

I'm having problem with Android Studio 3.0 and combination of kotlin and data binding. I'm not sure why, but option Settings -> Editor -> Data Binding -> Reference code generated by android studio is not working as it should be.

I've tried it on different AS 3.0 versions (Canary 3, Canary 5, Canary 6) with different kotlin (1.1.2-3, 1.1.3, 1.1.3-2) and databinding compiler ver. To be sure I have even created clean project and the same problem occurs. I'm sure that the problem lies in kotlin and databinding combination because in the same project databinding in java class is working just fine, files generated by databinding are updated with every change in .xml file.

I'm not going to paste my every gradle content file here because I have tried a lot of combination versions of kotlin and data binding. Below is one of them.

apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-kapt'

android {
    compileSdkVersion 25
    buildToolsVersion "25.0.2"
    defaultConfig {
        applicationId "com.dawidj.myapplication"
        minSdkVersion 21
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    dataBinding {
        enabled = true
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
    exclude group: 'com.android.support', module: 'support-annotations'
    })
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
    implementation 'com.android.support:appcompat-v7:25.4.0'
    testImplementation 'junit:junit:4.12'

    // Databinding
    kapt "com.android.databinding:compiler:$android_plugin_version"
}

repositories {
    mavenCentral()
}



buildscript {
    ext.android_plugin_version = '2.4.0-alpha7'
    ext.kotlin_version = '1.1.3'
    repositories {
        maven { url 'https://maven.google.com' }
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.0-alpha3'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        maven { url 'https://maven.google.com' }
        jcenter()
        mavenCentral()
    }
}

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

I've noticed that while i'm in java file after click (ctrl + click) on file generated by Data binding ex.:activity_main.xml -> ActivityMainBinding.java my screen is being moved directly to activity_main.xml file. After the same action in Kotlin class screen is being moved to ActivityMainBinding.java file.

It's very annoying problem becasue with every change in .xml file I'm forced to rebuild project in order to use data binding.

Any kind of help or information will be appreciated

EDIT: Invalidate caches / restart helps only to first project build. If I create new .xml layout it's working fine until project build.

1 Answers

Add following in you app build.gradle

android { /// Existing Code kapt { generateStubs = true } }

This may help.

Related