Binding code for Android Studio 3.0 not created by Android Studio

I have a problem with Android Studio 3.0 and a combination of kotlin and data binding. I’m not sure why, but the option "Settings" β†’ "Editor" β†’ "Data Binding" β†’ The link code generated by the Android studio does not work as it should.

I tried it in different versions of AS 3.0 (Canary 3, Canary 5, Canary 6) with different kotlin (1.1.2-3, 1.1.3, 1.1.3-2) and databinding ver compiler. Of course, I even created a clean project, and the same problem arises. I am sure that the problem lies in the combination of kotlin and databinding, because in the same project, data binding in the java class works fine, files created using data binding are updated with every change in the .xml file.

I am not going to embed my every gradle content file here because I have tried many combinational 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 noticed that while I'm in the java file after clicking (ctrl + click) in the file generated by the data binding ex.:activity_main.xml β†’ ActivityMainBinding.java, my screen moves directly to the file activity_main.xml. After the same action in the class screen Kotlin is moved to an ActivityMainBinding.java file.

This is a very nasty problem that occurs with every change to the .xml file. I have to rebuild the project to use data binding.

Any help or information would be appreciated.

EDIT: An invalid cache / restart only helps for the first build of the project. If I create a new .xml layout, it works fine before building the project.

+5
source share

Source: https://habr.com/ru/post/1269770/


All Articles