简体   繁体   中英

Android Studio 4.2 doesn’t recognize any syntax in KotlinScript Gradle build.gradle.kts, even though 4.1.3 works fine with Gradle 7.0

Versions

  • Android Studio 4.2
  • Gradle 7.0
  • AGP: 4.1.3 ( I see the same results with AGP 4.2 , so I am opting instead to keep as many variables constant as possible.)
  • Kotlin: 1.5
  • JDK: /Applications/Android\ Studio.app/Contents/jre/jdk/Contents/Home/bin/java -version is openjdk version "11.0.8" 2020-07-14
  • Mac OX Big Sur 11.3.1

After upgrading to Android Studio 4.2, my project cannot be built. All my KotlinScript files fail to be recognized by AS, and Gradle sync fails as well.

Gradle on the command-line continues to work correctly.

This is my top-level build.gradle.kts , and I see the same results for every module as well (this one is just one of several samples). Image with syntax highlighting issues is here: https://i.stack.imgur.com/bvjVz.png

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
  extra["kotlin_version"] = "1.5.0"

  repositories {
    google()
  }

  dependencies {
    classpath(kotlin("gradle-plugin", version = rootProject.extra["kotlin_version"] as String?))
    classpath("com.android.tools.build:gradle:4.1.3")
    classpath("com.squareup.sqldelight:gradle-plugin:1.4.4")
    classpath("com.github.ben-manes:gradle-versions-plugin:0.38.0")

    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
  }
}

plugins {
  id("com.github.ben-manes.versions") version "0.38.0"
  id("io.gitlab.arturbosch.detekt") version "1.16.0"
}

allprojects {
  repositories {
    google()
    jcenter()
    maven("https://jitpack.io")
  }
}

subprojects {
  apply {
    plugin("io.gitlab.arturbosch.detekt")
  }

  detekt {
    config = rootProject.files("detekt.yml")
    reports {
      html {
        enabled = true
        destination = file("build/reports/detekt.html")
      }
    }
  }
}

tasks.withType<KotlinCompile> {
  kotlinOptions {
    jvmTarget = "1.8"
  }
}

Summary of errors:

Cannot access 'java.lang.Object' which is a supertype of 'org.gradle.kotlin.dsl.KotlinBuildScript'. Check your module classpath for missing or conflicting dependencies
Cannot access 'java.lang.Comparable' which is a supertype of 'org.gradle.kotlin.dsl.KotlinBuildScript'. Check your module classpath for missing or conflicting dependencies

I tried making my project compatible with the latest versions of everything, including Gradle 7.0. The only variable that breaks the project is upgrading Android Studio to 4.2, with no changes to the source tree.

Is this a known issue / am I missing something obvious?

I am used to my project breaking every time the Android Gradle Plugin is updated, but this time, it's happening even without any changes to source.

I had the exact same issue this morning after I updated the Android Studio from 4.2.0 to 4.2.1 version on my Linux machine.

Here is how I fixed it:

  1. Open a "Project Structure" dialog.
  2. Choose "SDK Location" on the left side of the dialog window.
  3. Change "JDK location" path from build in to another one installed on your system. Like: /usr/lib/jvm/java-11-openjdk . And apply changes.
  4. Return build in "JDK location" path and apply changes.

Errors should be gone now.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM