Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 475
Mahdi Azadbar Avatar asked Nov 07 '17 19:11

Mahdi Azadbar


People also ask

Can I import Kotlin class in Java?

Kotlin code can be easily called from Java. For example, instances of a Kotlin class can be seamlessly created and operated in Java methods. However, there are certain differences between Java and Kotlin that require attention when integrating Kotlin code into Java.

Can you mix Kotlin and Java in Android Studio?

Adding Java source code to an existing Kotlin projectIf you already have the Java classes, you can just copy them to the project directories. You can now consume the Java class from Kotlin or vice versa without any further actions. lets you call it from Kotlin like any other type in Kotlin.


2 Answers

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.

like image 198
Eugen Pechanec Avatar answered Nov 01 '22 19:11

Eugen Pechanec


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.

like image 1
Faakhir Avatar answered Nov 01 '22 17:11

Faakhir