skip to Main Content

I made a Java project in Android Studio, and tried to put a file in Kotlin. But you can see that Android Studio doesn’t recognize Kotlin files in the same project that contains Java files. Can anyone help please?

Attached photos explaining better:

https://i.stack.imgur.com/sDNoV.png

https://i.stack.imgur.com/MwWbA.png

2

Answers


  1. Chosen as BEST ANSWER

    I discovered to fix this error. It has to put the following code in root build.gradle file:

    buildscript {
    ext.kotlin_version = '1.1.60'
        repositories {
            jcenter()
            maven {
                url 'https://maven.google.com'
            }
        }
    
        dependencies {
            classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        }
    }
    

    Thank you very to all that tried to help.


  2. Maybe you used Annotation in that class. Add kotlin-kapt plugin in build.gradle/module ,this may fix your problem. You can read this document for more guidence.

    plugins {
        id 'com.android.application'
        id 'kotlin-android'
        id 'kotlin-kapt' 
    //    id 'kotlin-android-extensions'
        id 'kotlin-parcelize' // this instead of kotlin-android-extensions
    }
    

    Then sync your project.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search