156

I installed the Kotlin plugin into my app (v. v1.1.1-release-Studio2.2-1) and then selected "Configure Kotlin in Project" I selected compiler and runtime version of 1.0.7. Kotlin updated my Gradle files. Now when I try to build in I get:

Error: A problem occurred configuring project ':app'. Could not resolve all dependencies for configuration ':app:_debugApkCopy'. Could not find org.jetbrains.kotlin:kotlin-stdlib-jre7:1.0.7. Required by:

MyApplication:app:unspecified

I'm not sure what I'm missing here.

Community
  • 1
  • 1
Mike6679
  • 5,547
  • 19
  • 63
  • 108

21 Answers21

237

replace

implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
                                                    ^
                                                    |
                                      JRE = Java Runtime Environment

with

implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
                                                    ^
                                                    |
                                       JDK = Java Development Kit

Since the version with jre is absolute , just replace and sync the project

Official Documentation here Thanks for the link @ ROMANARMY

Boken
  • 4,825
  • 10
  • 32
  • 42
leoelstin
  • 3,058
  • 1
  • 14
  • 11
  • 1
    Some helpful information in the [docs](http://kotlinlang.org/docs/reference/whatsnew12.html#kotlin-standard-library-artifacts-and-split-packages) about jdk and jre. – Roman Dec 16 '18 at 05:51
  • 1
    I believe one day Android team will make things a little easier not much just a little or at least they will write major changes in changelog with bold instead of burying it deep into the website to be mined out :)) – Farid Jan 26 '19 at 09:24
  • 35
    It took me a full minute of staring to see the difference between `jre` and `jdk`—I must be getting old. – James Wang Mar 15 '19 at 20:11
  • which file should i search for this? – Hamed Zakery Miab Dec 18 '21 at 11:12
  • 1
    funny I got the error that: Could not find org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.7.10. – Pascale Beaulac Mar 16 '23 at 17:22
32

In Project level build.gradle use only this version

ext.kotlin_version = '1.3.31'

Remove other versions

This will only work with the latest version of android studio 3.4

UPDATE: Try to use the latest version of kotlin with latest Android studio to avoid an error.

Patel Pinkal
  • 8,984
  • 4
  • 28
  • 50
  • 39
    An answer that specifies a magic version to use, without explanation, is not all that helpful and becomes even less helpful over time. Are you suggesting upgrading from a lower version? Or downgrading from a higher version because the higher version has a bug? – Don Hatch Dec 27 '17 at 20:08
  • 3
    @DonHatch this answer was given in March for android studio 2.2 which was getting error mention above in the question. It is not for android studio 3.0 or above. – Patel Pinkal Dec 28 '17 at 04:30
  • @0xalihn answer below has a correct solution without magic version number – Lou Morda Jan 22 '19 at 16:21
  • @PatelPinkal can you update your answer for latest android studio version. – Arbaz.in Jun 07 '19 at 05:10
  • @Arbaz.in try to install and use a new version of kotlin. May its help you. Also, note that your studio should be the latest version if you are using latest kotlin version. – Patel Pinkal Jun 07 '19 at 05:45
  • @PatelPinkal Sure ill do same – Arbaz.in Jun 07 '19 at 05:49
  • Ok, If it's working then edit this post or provide your answer here. So, others can have solutions. – Patel Pinkal Jun 07 '19 at 05:55
  • 1
    i updated answer as per latest version of Android studio – Arbaz.in Jun 07 '19 at 10:09
  • @Arbaz.in I can't see any update in answer. Please post your answer in a comment – Patel Pinkal Jun 07 '19 at 12:57
28

If you hereafter removing Jcenter from Gradle then add this to your gradle

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



allprojects {
    repositories {
        google()
        mavenCentral()
        maven { url "https://jitpack.io" }
    }
}

So main point is that, add mavenCentral() and maven { url "https://jitpack.io" } in gradle

iamkdblue
  • 3,448
  • 2
  • 25
  • 43
24

The split of kotlin-stdlib into kotlin-stdlib-jre7 and kotlin-stdlib-jre8 was only introduced with Kotlin 1.1, that's why the dependency cannot be resolved, the package version simply does not exist.

It looks like the update to your project files failed at some point and set the Kotlin version to 1.0.7. If this is a new project and there's nothing holding you back from using 1.1.1, I'd switch to that. Your problem should be gone after doing this.

  • 5
    Thank you for explaining. Several answers say use 1.1.1 without explanation, which will make the answers rapidly become useless in the future. – Don Hatch Dec 27 '17 at 20:11
12

In "build.gradle" file, change current Kotlin version that line and press synk:

ext.kotlin_version = '1.1.1'

/// That will look like:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

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

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}
Mihail Salari
  • 1,471
  • 16
  • 17
11

Starting with Kotlin 1.1.2, the dependencies with group org.jetbrains.kotlin are by default resolved with the version taken from the applied plugin. You can provide the version manually using the full dependency notation like:

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

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"
0xAliHn
  • 18,390
  • 23
  • 91
  • 111
11

A new solution if you use Android Studio 3.2, I solved this issue by added mavenCentral() to build.gradle of the project:

buildscript {
    ext.kotlin_version = '1.3.0'
    repositories {
        mavenCentral()
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.2.1'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

    }
}

allprojects {
    repositories {
        mavenCentral()
        google()
        jcenter()
    }
}

You should add the line as this order, the credited is for this answer

Mohamed ElSawaf
  • 229
  • 2
  • 8
5
buildscript {
    **ext.kotlin_version = '1.1.1'**  //Add this line
    repositories {
        **jcenter()**                 //Add this line
        google()
    }
    dependencies {
//        classpath 'com.android.tools.build:gradle:3.0.1'
        classpath 'com.android.tools.build:gradle:3.1.0'

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

allprojects {
    repositories {
        **jcenter()**                 //Add this line
        google()
        maven { url "https://jitpack.io" }
    }
}
MoxGeek
  • 458
  • 6
  • 17
  • 1
    You could elaborate on how this improves Mihail Salari's answer, on which it seems to be based. – Nemo Mar 31 '18 at 06:56
3

I have solved this issue using deselection of the Offline work option in Settings

enter image description here

andreikashin
  • 1,528
  • 3
  • 14
  • 21
3

If you are using Android Studio 3.2 & above,then issue will be solved by adding google() & jcenter() to build.gradle of the project:

repositories {
        google()
        jcenter()
}
Suraj Kumar
  • 5,547
  • 8
  • 20
  • 42
vikas
  • 139
  • 1
  • 8
2

This is what worked for me: Using Gradle 4.8.1

buildscript {
    ext.kotlin_version = '1.1.1' 
repositories {
    jcenter()
    google()
}
dependencies {
    classpath 'com.android.tools.build:gradle:3.1.0'}
}
allprojects {
    repositories {
        mavenLocal()
        jcenter()
        google()
        maven {
            url "$rootDir/../node_modules/react-native/android"
        }
    maven {
            url 'https://dl.bintray.com/kotlin/kotlin-dev/'
    }
  }
}   
Olusola Omosola
  • 847
  • 9
  • 9
1
  1. Please check current version of your Kotlin in below path,

    C:\Program Files\Android\Android Studio\gradle\m2repository\org\jetbrains\kotlin\kotlin-stdlib\1.0.5

change to that version (1.0.5) in project level gradle file.

You can see in your above path does not mentioned any Java - jre version, so remove in your app level gradle file as below,

compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
mallaudin
  • 4,744
  • 3
  • 36
  • 68
1

build.gradle (Project)

buildScript {
    ...
    dependencies {
        ...
        classpath 'com.android.tools.build:gradle:4.0.0-rc01'
    }
} 

gradle/wrapper/gradle-wrapper.properties

...
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip

Some libraries require the updated gradle. Such as:

androidTestImplementation "org.jetbrains.kotlinx:kotlinx-coroutines-test:$coroutines"

GL

Braian Coronel
  • 22,105
  • 4
  • 57
  • 62
0

In case a (transitive) dependency still uses the jre variant of the Kotlin library, you can force the use of the jdk variant with the help of a resolution strategy:

configurations.all {
    resolutionStrategy {
        eachDependency { DependencyResolveDetails details ->
            details.requested.with {
                if (group == "org.jetbrains.kotlin" && name.startsWith("kotlin-stdlib-jre")) {
                    details.useTarget(group: group, name: name.replace("jre", "jdk"), version: version)
                    details.because("Force use of 'kotlin-stdlib-jdk' in favor of deprecated 'kotlin-stdlib-jre'.")
                }
            }
        }
    }
}
Brian
  • 2,130
  • 22
  • 29
0

After fixing the build.gradle version, It started working 4.0.0 to 3.5.0

0

Reload sdk maybe the problem is solved

0

If you are facing issues with your Flutter project, updating Gradle could be a solution. Here are the steps you can follow:

  1. Open your build.gradle(app) file and update the following line of code under the dependencies section:

dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.8.0"

  1. Next, open your build.gradle(android) file and update the following line of code under the dependencies section:

classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.8.0"

By making these updates, you should be able to resolve any issues related to Gradle and successfully run your Flutter project. Remember to always keep your dependencies up to date to ensure the smooth running of your project.

Devplanet
  • 770
  • 8
  • 7
0

I put my experience here in case someone knows the reason why (2) worked. This happened to me twice with the same project:

(1) I cloned a flutter project and successfully built it. But the second time I tried to build it again, this error happened. Tried this and that, nothing worked. Then I deleted and cloned the project again, built it, and it successfully ran.

(2) Still using the very same re-cloned project in (1), after 3 days it worked wonderfully, in fourth day it suddenly happened again. I simply opened Android Studio and trying to run the app, and it happened again. This time, I saw Changes (in commit window) in files and the only file related with project setting was pubspec.lock. I deleted it, rebuilt, and it successfully ran.

Konayuki
  • 674
  • 1
  • 9
  • 21
0

This issue occured when I updated from Electric eel to Falmingo. I solved it like this:

Goto File->Project Structure-> SDK Location -> JDK (Gradle Settings)

In the Gradle JDK drop down, choose Embedded JDK (Try diffrent options if this does not work, preferably the latest JDK)

Now try sync project with gradle files.

Reejesh PK
  • 658
  • 1
  • 11
  • 27
-1

Simple Steps:

  1. Click File > Project Structure

  2. Click Dependencies > Find and Click org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.21 (or whatever your current version is)

  3. Under Details > update section, click [update variable][update dependencies]

  4. Click Ok

Narendra_Nath
  • 4,578
  • 3
  • 13
  • 31
-2

In my case problem solved by adding the following lines in build.gradle file:

allprojects {
repositories {
            jcenter()                
            google()
         maven { url "https://jitpack.io" } //remember to add this line
  }
}
Salahuddin Ahmed
  • 4,854
  • 4
  • 14
  • 35
fazal ur Rehman
  • 330
  • 2
  • 5