Android Studio throws build error in Kotlin project which calls static method in java interface

后端 未结 4 2105
挽巷
挽巷 2021-02-20 11:45

I have a Kotlin project in Android Studio. I am calling a static method in Java interface from the Kotlin code. The build fails with the error,

Calls to static m         


        
4条回答
  •  情话喂你
    2021-02-20 12:08

    Proper way to set Kotlin compile options in android gradle. Make these changes to your app level Build.gradle

    Change

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

    to

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

    Then write this task

    tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
        sourceCompatibility = JavaVersion.VERSION_1_8
        targetCompatibility = JavaVersion.VERSION_1_8
    
        kotlinOptions {
            jvmTarget = '1.8'
            apiVersion = '1.1'
            languageVersion = '1.1'
        }
    }
    

    just below(not necessarily)

    repositories {
        mavenCentral()
    }
    

    For details, refer here

提交回复
热议问题