28

i use android studio 3.0 and some old java class Convert Java to Kotlin. after that Kotlin class cant import in java class! in below you can see my gradle and a picture of my error.

module build.grade

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.0'
        classpath 'com.google.gms:google-services:3.1.0'

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

allprojects {
    repositories {
        jcenter()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

in app level build.gradle in normally i use gradle code and in android 3.0 i think we need any thing

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion '26.0.2'
    defaultConfig {
        applicationId "com.idehnavazan.beautifierclient"
        minSdkVersion 14
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        multiDexEnabled true
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    dataBinding {
        enabled = true
    }


}
repositories {
    mavenCentral()
    jcenter()
    maven { url 'https://maven.google.com' }
    maven { url 'https://jitpack.io' }


}
dependencies {
    compile 'com.android.support:multidex:1.0.1'  
    compile 'com.android.support:appcompat-v7:25.3.1'
    compile 'com.github.rey5137:material:1.2.2'
    compile 'com.android.support:cardview-v7:25.3.1'

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

enter image description here

Azzabi Haythem
  • 2,318
  • 7
  • 26
  • 32
Mahdi Azadbar
  • 1,330
  • 3
  • 17
  • 24

5 Answers5

64

To work with Kotlin files you need to add Kotlin to your project.

project/build.gradle

buildscript {
    ext.kotlinVersion = '1.1.51'
    repositories {
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.0'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
    }
}

project/module/build.gradle

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

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
}

What's next

Since you're using support library 25.3.1 and Android plugin 3.0.0 your next question will probably be this: style attribute '@android:attr/windowEnterAnimation' not found.

Eugen Pechanec
  • 37,669
  • 7
  • 103
  • 124
1

I have added all kotlin classes in separate folder and it work for me! Keep your java classes separate from kotlin. I was having

app:compileDebugJavaWithJavac Kotlin class calling from java:  error: cannot find symbol 

compile time error.

Fakhar
  • 3,946
  • 39
  • 35
0

My issue was that I have imported a submodule using testImplementation instead of implementation inside of module gradle file that is declaring your module as a dependency.

Changing the dependency declaration fixed it for me.

bboyairwreck
  • 331
  • 3
  • 6
0

I am also new to kotlin/android and was using ViewBinding. I was renaming an xml-file when this type of error occured. I just added:

dataBinding {
        enabled = true
    }

to the build.gradle(module)-file and it now works. To be honest, I never understood the difference between view- and data-binding

LaurentBaj
  • 451
  • 5
  • 10
0

kotlin/android and was using ViewBinding. just add this inside build.gradle(module)-file

viewBinding{
        enabled = true
    }
Cashpi App
  • 11
  • 3
  • This will enable dataBinding, which is not the same as viewBinding (you could say it is viewBinding and more: https://stackoverflow.com/questions/58040778/android-difference-between-databinding-and-viewbinding), if you want to enable viewBinding only, replace "dataBinding" with "viewBinding" in your answer – JustSightseeing Sep 24 '22 at 20:55
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Sep 26 '22 at 13:15