kotlin-stdlib-jre7 is deprecated. Please use kotlin-stdlib-jdk7 instead

AndroidKotlin

Android Problem Overview


Yesterday I updated Android Studio Version and Kotlin plugin version.

Android Studio Version: 3.1.2

Kotlin Version: 1.2.41

When I create an Android project using this configuration, I get Kotlin Compiler warning saying

> w: /home/ganeshtikone/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-jre7/1.2.41/9e7a6f582de73d9cdc6c56ef4e23604a0ee55768/kotlin-stdlib-jre7-1.2.41.jar: kotlin-stdlib-jre7 is deprecated. Please use kotlin-stdlib-jdk7 instead

Changed as per suggestion, then I am getting following error

> Unexpected inputs: ImmutableJarInput{name=org.jetbrains.kotlin:kotlin-stdlib-jre7:1.2.41, file=/home/ganeshtikone/Workspace/May-2018/fhs/app/build/intermediates/transforms/desugar/stage/debug/45.jar, contentTypes=CLASSES, scopes=EXTERNAL_LIBRARIES, status=REMOVED}

Android Solutions


Solution 1 - Android

Go to Tools > Kotlin > Configure Kotlin Plugin Updates and check for updates then in your app gradle file replace jre with jdk

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

Solution 2 - Android

#Important Update

###Must check JDK version before setting config

Kotlin gradle config page has detailed information about this.

First of all check your kotlin version in gradle file.

> ## if (kotlin_version == '1.2.x' ) (Use jdk NOT jre)

First check your jdk version in File > Project Structure.

sc

Or check in build.gradle

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}

if (jdk_version == 1.8)

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

if (jdk_version == 1.7)

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

if (jdk_version is < 1.7)

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

else if(NO jdk version is set in Project Structure)

if(Android_Studio_Version < 2.2.1){
   your_jdk_version = 1.7;
}
else {
   your_jdk_version = 1.8;
}

Because Android Studio is bundled with jdk 1.8 since 2.2.1 version.

> ##2. else if ( kotlin_version == '1.1.x') (Use jre NOT jdk)

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

###Update Kotlin Version?

You can update Kotlin version from Tools > Kotlin > Configure Kotlin Updates

Solution 3 - Android

Something is transitively importing those libraries. Run Gradle task dependencies to figure out what.

In my case, it was io.vertx:vertx-lang-kotlin-coroutines:3.5.1.

If there is no update for the dependency, there is not much you can do about it

Solution 4 - Android

After reading Kotlin Gradle Script Topic I find out that some ponits

> If you're targeting JDK 7 or JDK 8, you can use extended versions of the Kotlin standard library which contain additional extension functions for APIs added in new JDK versions. Instead of kotlin-stdlib, use one of the following dependencies: > > compile "org.jetbrains.kotlin:kotlin-stdlib-jdk7"
> compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8"

I used implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8" in my project. I think it's because of compileOptions set in build.graddle

compileOptions {
    sourceCompatibility JavaVersion.VERSION_1_8
    targetCompatibility JavaVersion.VERSION_1_8
}

Solution 5 - Android

You must swap the codes below:

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

Not jre > jdk

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

Solution 6 - Android

Change SDK7 to Java SDK8 try this:

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"

}

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionGanesh TikoneView Question on Stackoverflow
Solution 1 - AndroidAman SaxenaView Answer on Stackoverflow
Solution 2 - AndroidKhemraj SharmaView Answer on Stackoverflow
Solution 3 - AndroidNikola MihajlovićView Answer on Stackoverflow
Solution 4 - AndroidGanesh TikoneView Answer on Stackoverflow
Solution 5 - Androidsamet kayaView Answer on Stackoverflow
Solution 6 - AndroidChristian GrandezView Answer on Stackoverflow