【问题标题】:Android Studio errors in files but project compiles and run: Unresolved reference文件中的 Android Studio 错误但项目编译并运行:未解决的参考
【发布时间】:2021-08-25 22:19:27
【问题描述】:

这个问题解决了。

项目编译良好。但是,Android Studio 4.0.1 以红色显示对一个特定库的引用并显示“未解决的引用:启动”。

我已经尝试了各种选项,例如 1) 使缓存/重新启动无效 2) 删除构建目录 3) 清理并重建 4)4) 删除 .idea、.gradle 但似乎没有任何效果。 This is the import code image This is the code I'm using

buildscript {
    ext.kotlin_version = '1.3.71'
    ext.navigation_version = '2.2.0-rc04'
    repositories {
        google()
        jcenter()
        
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:4.0.1'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$navigation_version"
        // 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'
apply plugin: 'kotlin-kapt'
apply plugin: "androidx.navigation.safeargs.kotlin" //새로 추가

android {
    compileSdkVersion 28
    buildToolsVersion "29.0.0"

    defaultConfig {
        applicationId "com.example.sampleapp"
        minSdkVersion 21
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        javaCompileOptions {
            annotationProcessorOptions {
                arguments += ["room.schemaLocation":
                                      "$projectDir/schemas".toString()]
            }
        }
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility = 1.8
        targetCompatibility = 1.8
    }

    kotlinOptions {
        jvmTarget = "1.8"
    }

    dataBinding {
        enabled = true
    }
    sourceSets {
        // Adds exported schema location as test app assets.
        androidTest.assets.srcDirs += files("$projectDir/schemas".toString())
    }

}

dependencies {
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
    def lifecycle_version = "2.2.0"
    def room_version="2.3.0-alpha01"
    def nav_version = "2.2.0-rc04"

    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.core:core-ktx:1.3.1'
    implementation 'androidx.activity:activity-ktx:1.1.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'

    implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.2.0-alpha01'
    implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.2.0-alpha01'

    implementation "androidx.recyclerview:recyclerview:1.1.0"
    // For control over item selection of both touch and mouse driven selection
    implementation "androidx.recyclerview:recyclerview-selection:1.1.0-rc01"
    kapt 'androidx.room:room-compiler:2.3.0-alpha01'

    implementation 'com.github.bumptech.glide:glide:4.11.0'
    kapt 'com.github.bumptech.glide:compiler:4.11.0' //annotationProcessor -> kapt

    testImplementation "androidx.room:room-testing:2.3.0-alpha01"

    ...
}

【问题讨论】:

  • @Ganesh 我不认为是重复的,链接是关于项目无法编译的,问题是关于项目编译但显示未解决的引用
  • @Chaeun Gong 你能解决这个问题吗?你是如何找到工作的?
  • 不重复。我只是关闭并打开计算机,它工作。我认为这只是android studio的错误。

标签: android kotlin


【解决方案1】:

就我而言,File 菜单中的Invalidate Caches/Restart 解决了这个问题。无需重启电脑。

【讨论】:

  • 没有一个答案有帮助。在我的情况下,帮助更改协程版本。从:1.5.0 到 1.5.2
猜你喜欢
  • 2019-03-19
  • 1970-01-01
  • 1970-01-01
  • 2020-04-20
  • 2021-02-17
  • 1970-01-01
  • 2023-01-17
  • 2018-05-31
  • 1970-01-01
相关资源
最近更新 更多