Search code examples
android-studiokotlinbuildsrc

Unresolved reference on fly in buildSrc


I'm trying to write code in buildSrc in Android project, but it allways notice me Unresolved reference: xxx, like this:

Unresolved reference

Although the compilation can pass, it is always inconvenient. I've tried restarting the IDE, Invalidate Caches, reinstalling the IDE, but it dosen't work, so how to solve this problem? Thank you!

/buildSrc/build.gradle.kts:

plugins {
    java
    `kotlin-dsl`
}

java {
    sourceCompatibility = JavaVersion.VERSION_11
    targetCompatibility = JavaVersion.VERSION_11
}

repositories {
    gradlePluginPortal()
    google()
    mavenCentral()
}

dependencies {
    // https://mvnrepository.com/artifact/net.dongliu/apk-parser
    implementation("net.dongliu:apk-parser:2.6.10")
}

tasks.test {
    useJUnitPlatform()
}

tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
    kotlinOptions.jvmTarget = "11"
}

/build.gradle.kts:

// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
    val androidVer = "7.3.1"
    id("com.android.application") version androidVer apply false
    id("com.android.library") version androidVer apply false

    val ktVer = "1.7.20"
    id("org.jetbrains.kotlin.android") version ktVer apply false
}

Solution

  • Solution: File -> Repire IDE, the step of Reindex project can solve this problem.