Updated to Android Studio 3.0. Getting a “Kotlin n

2019-02-16 11:19发布

问题:

I just updated to Android Studio 3.0 and I'm getting this error with an existing project:

Kotlin not configured

When I go to Tools>Kotlin>Configure Kotlin in Project, I get an error saying "no configurators available". Also get the error below with the red java:

I've also tried:

  • Restarting
  • Clean and Rebuild
  • Invalidate caches/restart.

回答1:

I first tried with invalidate cache/ restart option but it doesn't help me.

When I updated Kotlin to 1.1.60 in project's gradle file, problem is solved.

Also, use this in app's gradle for stdlib

implementation "org.jetbrains.kotlin:kotlin-stdlib:1.1.60" 

instead of

implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:1.1.60"


回答2:

In Android Studio, click on File -> Invalidate Caches / Restart... , then select "Invalidated and Restart". This solved my problem.



回答3:

The only thing that worked for me was to uninstall the kotlin plugin (File -> Settings -> Plugins -> Kotlin press uninstall) and after a restart of Android Studio reinstall the plugin.



回答4:

I have faced this issue recently... when I updated to Android Studio 3.1 .

I did a few things to fix this.

  1. First I updated the Kotlin version in my app gradle file and added

    implementation "org.jetbrains.kotlin:kotlin-stdlib:1.2.31" 
    

    in my app gradle file. But this alone didn't fix it.

  2. Then uninstalled the kotlin plugin from settings, restarted Android Studio and installed it again.

EDIT :

This is my project gradle file

buildscript {
   ext.kotlin_version = '1.2.31'
   repositories {
      jcenter()
      google()
    }
   dependencies {
      classpath 'com.android.tools.build:gradle:3.1.1'
      classpath 'com.google.gms:google-services:3.1.0'
      classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.2.31"

   }
 }

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

And this is my app gradle file

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'

android {

   compileSdkVersion 27

   buildToolsVersion '27.0.3'

   defaultConfig {
       ...
    }

    buildTypes {
        ...
    }

    sourceSets {
         main.java.srcDirs += 'src/main/kotlin'
     }

     kapt { generateStubs = true }


}
repositories {
     ...
}


dependencies {
    ...
    ...
    implementation "org.jetbrains.kotlin:kotlin-stdlib:1.2.31"
    ...
    ...

 }

apply plugin: 'com.google.gms.google-services'


回答5:

Closing and restarting Android Studio works for me in that case. Important is that there are no other projects opened in Android Studio before you close it. I suspect that closing Android Studio with multiple opened project windows sometimes messes up the configuration especially after plugin upgrades etc.



回答6:

None of the other solutions solved my problem. I ended up figuring out that the problem lied in the google services version. Just update it to the latest.

Top level gradle at dependencies:

classpath 'com.google.gms:google-services:4.1.0'


回答7:

Important Update

You should check JDK version before setting config

Kotlin gradle config page has detailed information about this.

Step 1

Check kotlin version in project level gradle file.

classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

For kotlin_version '1.2.x' Use jdk NOT jre

Step 2

Check JDK version in File > Project Structure

Or check in build.gradle

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}

If no JDK version is set in Project Structure, then choose by Android Studio version

  • JDK version is 1.7 for Android Studio Version < 2.2.1
  • JDK version is 1.8 for Android Studio Version < 2.2.1

Because Android Studio is bundled with jdk 1.8 since 2.2.1 version.

You have 3 options of kotlin stdlib, choose according JDK version

implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version" //jdk_version == 1.8
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" //jdk_version == 1.7
implementation"org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" // jdk_version is < 1.7

if kotlin version is'1.1.x' Use jre NOT jdk

implementation"org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version" // or jre8

Update Kotlin Version?

You can update Kotlin version from Tools > Kotlin > Configure Kotlin Updates