Daw*_*idJ 8 data-binding android kotlin android-studio android-databinding
我遇到了Android Studio 3.0以及kotlin和数据绑定的组合问题.我不知道为什么,但选项设置 - >编辑器 - >数据绑定 - > android studio生成的参考代码不能正常工作.
我已经尝试了不同的AS 3.0版本(Canary 3,Canary 5,Canary 6)和不同的kotlin(1.1.2-3,1.1.3,1.1.3-2)和数据绑定编译器ver.为了确保我甚至创建了干净的项目,也会出现同样的问题.我确信问题在于kotlin和数据绑定组合,因为在同一个项目中,java类中的数据绑定工作正常,数据绑定生成的文件会随着.xml文件中的每次更改而更新.
我不会在这里粘贴我的每个gradle内容文件,因为我已经尝试了很多kotlin和数据绑定的组合版本.下面是其中之一.
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
}
Run Code Online (Sandbox Code Playgroud)
我注意到,当我点击(ctrl + click)数据绑定ex.:activity_main.xml - > ActivityMainBinding.java生成的文件后,我在java文件中,我的屏幕被直接移动到activity_main.xml文件.在Kotlin类屏幕中的相同操作被移动到ActivityMainBinding.java文件之后.
这是非常恼人的问题因为.xml文件中的每次更改我都被迫重建项目以便使用数据绑定.
任何形式的帮助或信息将不胜感激
编辑:无效的缓存/重启只能帮助第一个项目构建.如果我创建新的.xml布局,它可以正常工作直到项目构建.
RKS*_*RKS -1
添加以下内容app build.gradle
android {
/// Existing Code
kapt {
generateStubs = true
}
}
这可能会有所帮助。
| 归档时间: |
|
| 查看次数: |
1113 次 |
| 最近记录: |