android - 使用 Kotlin/Firebase 完成 Android Studio 代码 - 行为不端
问题描述
更新:当我在类的方法中编写 lambda 时,总是会出现此错误,并且我引用了该类的变量。当我在方法中引用变量时,它不会出现。
我正在阅读使用 Firebase 进行 Kotlin 开发的简单指南。但不知何故,Android Studio 现在的代码完成有点被这个破坏了。
我有一个名为 FirestoreUtil 的类private val currentUserDocRef
,即使在该类中编写,我也无法使代码完成正常工作。
这个问题适用于我在这个项目中编写的所有类。
我会开始输入'currentUs'等...看到它建议变量及其类型。我选择它,但不仅仅是写
当前用户文档参考
它反而抽出
com.leonhardprintz.firemessage.utils.FirestoreUtil.currentUserDocRef
在尝试完成我自己编写的变量时,它始终如一地这样做。外部库加载就好了。
有没有人遇到过这个?
这是我的gradle文件的内容
buildscript {
ext.kotlin_version = '1.2.41'
ext.anko_version = '0.10.5'
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.2'
classpath "org.jetbrains.kotlin:kotlin-gradle- plugin:$kotlin_version"
classpath 'com.google.gms:google-services:4.0.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
和
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android {
compileSdkVersion 27
defaultConfig {
applicationId "com.leonhardprintz.firemessage"
minSdkVersion 21
targetSdkVersion 27
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
//kotlin
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
//support
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:design:27.1.1'
implementation 'com.android.support.constraint:constraint-layout:1.1.1'
implementation 'com.android.support:support-vector-drawable:27.1.1'
//firebase
implementation 'com.google.firebase:firebase-core:16.0.0'
implementation 'com.google.firebase:firebase-firestore:17.0.1'
implementation 'com.google.firebase:firebase-auth:16.0.1'
implementation 'com.google.firebase:firebase-storage:16.0.1'
//firebase-ui
implementation 'com.firebaseui:firebase-ui-auth:4.0.1'
implementation 'com.firebaseui:firebase-ui-storage:4.0.1'
//glide
implementation 'com.github.bumptech.glide:glide:4.7.1'
implementation 'com.android.support:support-v4:27.1.1'
kapt 'com.github.bumptech.glide:compiler:4.7.1'
//groupie
implementation 'com.xwray:groupie:2.0.3'
implementation 'com.xwray:groupie-kotlin-android-extensions:2.0.3'
//anko
implementation "org.jetbrains.anko:anko:$anko_version"
implementation "org.jetbrains.anko:anko-design:$anko_version"
implementation "org.jetbrains.anko:anko-coroutines:$anko_version"
//test
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
apply plugin: 'kotlin-kapt'
kotlin {
experimental {
coroutines "enable"
}
}
androidExtensions {
experimental = true
}
}
apply plugin: 'com.google.gms.google-services'
解决方案
我也有同样的经历。这是 Android Studio Kotlin 插件中的一个错误。它不会影响您的代码,只需删除不必要的单词。
这确实很烦人,即使是现在也时有发生。所以让我们等到有人解决这个问题。