Android Studio 未解析参考.项目编译 [英] Android Studio unresolved reference. Project compiles
问题描述
升级 Android Studio 后,一个没有问题的项目开始在编辑器中显示问题.我有很多 Unresolved Reference
错误.支持库(support-v4、support-v7)下的任何内容.
After upgrading Android Studio, a project with no issues started showing issues in the editor. I have lots of Unresolved Reference
errors. Anything under the support libraries (support-v4, support-v7).
在上面的屏幕截图中,显示为红色的任何内容都无法解析并显示为错误.我也在使用 Lifecycle 组件和 Room 数据库.他们似乎也有问题.看起来接口可以找到,但类不能.
In the screen capture above, anything showing in red isn't resolving and showing as an error. I am also using Lifecycle components and Room database. They seem to have issues as well. Looks like interfaces can be found but classes can't.
例如,在我使用 Room
的课程之一中,
For example, in one of my classes using Room
,
android.arch.persistence.room.Database
和 android.arch.persistence.room.TypeConverters
解析正确,但
android.arch.persistence.room.Database
and android.arch.persistence.room.TypeConverters
resolve correctly, but
android.arch.persistence.room.Room
和 android.arch.persistence.room.RoomDatabase
没有.
注意:该项目在 Android 模拟器和设备上构建和运行良好,没有任何问题.它使用 Android Studio 上的构建按钮构建和运行,没有任何错误.我没有收到任何 Class not found 错误.这只是 Android Studio 编辑器中的一个问题.我已经重新启动了 Android Studio,清理并重建了项目.
Note: The project builds and runs fine on Android emulators and devices without any issues. It builds and runs using the build button on Android Studio without any errors. I'm not getting any Class not found errors. This is just an issue inside the Android Studio editor. I have already restarted Android Studio, cleaned and rebuilt the project.
这是我的项目构建文件:
Here's my project build file:
buildscript {
ext.kotlin_version = '1.2.70'
ext.serialization_version = '0.6.2'
ext.gradle_plugin_version = '3.2.0'
repositories {
google()
jcenter()
maven { url "https://jitpack.io" }
maven { url "https://kotlin.bintray.com/kotlinx" }
}
dependencies {
classpath "com.android.tools.build:gradle:3.2.1"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "org.jetbrains.kotlinx:kotlinx-gradle-serialization-plugin:$serialization_version"
}
}
allprojects {
repositories {
google()
jcenter()
maven { url 'https://jitpack.io' }
maven { url "https://kotlin.bintray.com/kotlinx" }
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
ext {
roomVersion = '1.1.1'
archLifecycleVersion = '1.1.1'
buildToolsVersion = '28.0.3'
supportLibVersion = '28.0.0'
}
和模块构建文件:
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'
apply plugin: 'kotlinx-serialization'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.example.project"
minSdkVersion 19
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
multiDexEnabled true
kapt {
arguments {
arg("room.schemaLocation", "$projectDir/schemas".toString())
}
}
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
flavorDimensions 'version'
productFlavors {
live {
dimension 'version'
}
dev {
dimension 'version'
versionNameSuffix '-dev'
}
}
buildToolsVersion "$rootProject.buildToolsVersion"
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
dataBinding {
enabled = true
}
}
kotlin {
experimental {
coroutines 'enable'
}
}
dependencies {
implementation "com.android.support:multidex:1.0.3"
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
implementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
implementation "org.jetbrains.kotlinx:kotlinx-serialization-runtime:$serialization_version"
// Support and google services
implementation "com.android.support:support-compat:$rootProject.supportLibVersion"
implementation "com.android.support:support-core-utils:$rootProject.supportLibVersion"
implementation "com.android.support:support-core-ui:$rootProject.supportLibVersion"
implementation "com.android.support:support-media-compat:$rootProject.supportLibVersion"
implementation "com.android.support:support-fragment:$rootProject.supportLibVersion"
implementation "com.android.support:design:$rootProject.supportLibVersion"
implementation "com.android.support:appcompat-v7:$rootProject.supportLibVersion"
implementation "com.android.support:gridlayout-v7:$rootProject.supportLibVersion"
implementation "com.android.support:preference-v7:$rootProject.supportLibVersion"
implementation "com.android.support.constraint:constraint-layout:1.1.3"
implementation "com.android.support:support-annotations:$rootProject.supportLibVersion"
implementation "com.android.support:support-vector-drawable:$rootProject.supportLibVersion"
implementation "com.android.support:recyclerview-v7:$rootProject.supportLibVersion"
implementation "com.google.android.gms:play-services-plus:15.0.1"
// Rx
implementation "io.reactivex.rxjava2:rxandroid:2.1.0"
implementation "io.reactivex.rxjava2:rxjava:2.2.2"
// Retrofit
implementation "com.google.code.gson:gson:2.8.5"
implementation "com.squareup.retrofit2:retrofit:2.4.0"
implementation "com.squareup.retrofit2:converter-gson:2.4.0"
implementation "com.squareup.retrofit2:adapter-rxjava2:2.4.0"
implementation "com.squareup.okhttp3:logging-interceptor:3.11.0"
// Testing
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"
///---
// java 8
implementation "android.arch.lifecycle:common-java8:$archLifecycleVersion"
// Room components
implementation "android.arch.persistence.room:runtime:$rootProject.roomVersion"
annotationProcessor "android.arch.persistence.room:compiler:$rootProject.roomVersion"
androidTestImplementation "android.arch.persistence.room:testing:$rootProject.roomVersion"
kapt "android.arch.persistence.room:compiler:$rootProject.roomVersion"
// Lifecycle components
implementation "android.arch.lifecycle:extensions:$rootProject.archLifecycleVersion"
kapt "android.arch.lifecycle:compiler:$rootProject.archLifecycleVersion"
annotationProcessor "android.arch.lifecycle:compiler:$rootProject.archLifecycleVersion"
}
推荐答案
我遇到了同样的问题.它与新的 AndroidX 库和迁移有关.
I had the same problem. It is related with new AndroidX libraries and migration on it.
Try File -> Open -> 然后点击 build.gradle 重新打开项目.
Try File -> Open -> and click build.gradle to reopen project.
这篇关于Android Studio 未解析参考.项目编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!