Android Studio未解决的参考.项目编译 [英] Android Studio unresolved reference. Project compiles

查看:118
本文介绍了Android Studio未解决的参考.项目编译的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

升级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.Databaseandroid.arch.persistence.room.TypeConverters可以正确解析,但是

android.arch.persistence.room.Database and android.arch.persistence.room.TypeConverters resolve correctly, but

android.arch.persistence.room.Roomandroid.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.

尝试文件->打开->并单击build.gradle重新打开项目.

Try File -> Open -> and click build.gradle to reopen project.

这篇关于Android Studio未解决的参考.项目编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆