error: cannot find symbol class for add kotlin class into java class in android studio 3.0 stable
Asked Answered
G

5

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

Gilliam answered 7/11, 2017 at 19:33 Comment(3)
This isn't a questions...Brody
i add some detail. i hope help youGilliam
Unrelated: That's not how you create fragments. Just call the constructor CategoryFragment() instead of instantiate.Cascade
C
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.

Cascade answered 7/11, 2017 at 20:26 Comment(1)
Still the valid answer in 2022.Otocyst
S
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.

Saval answered 8/9, 2019 at 10:0 Comment(0)
W
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.

Windburn answered 8/3, 2021 at 17:37 Comment(0)
P
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

Parsonage answered 16/5, 2021 at 13:40 Comment(0)
I
0

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

viewBinding{
        enabled = true
    }
Impetuous answered 19/9, 2022 at 3:32 Comment(2)
This will enable dataBinding, which is not the same as viewBinding (you could say it is viewBinding and more: #58041278), if you want to enable viewBinding only, replace "dataBinding" with "viewBinding" in your answerSilicious
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.Alberich

© 2022 - 2024 — McMap. All rights reserved.