首页 文章

Kotlin错误:找不到org.jetbrains.kotlin:kotlin-stdlib-jre7:1.0.7

提问于
浏览
59

我将Kotlin插件安装到我的应用程序(v.v1.1.1-release-Studio2.2-1)中,然后选择“在项目中配置Kotlin”我选择了1.0.7的编译器和运行时版本 . Kotlin更新了我的Gradle文件 . 现在,当我尝试构建时,我得到:

错误:配置项目':app'时出现问题 . 无法解析配置':app:_debugApkCopy'的所有依赖项 . 找不到org.jetbrains.kotlin:kotlin-stdlib-jre7:1.0.7 . 要求:MyApplication:app:unspecified

我不确定我在这里缺少什么 .

14 回答

  • 0

    更换

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

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

    由于具有jre的版本是绝对的,只需替换和同步项目

    官方文档here感谢您的链接@ ROMANARMY

    快乐编码:)

  • 2

    在项目级别 build.gradle 仅使用此版本

    ext.kotlin_version ='1.1.1'

    删除其他版本

    编辑:这只适用于Android Studio 2.X

  • 25

    kotlin-stdlib 拆分为 kotlin-stdlib-jre7kotlin-stdlib-jre8 仅在Kotlin 1.1中引入,这就是无法解决依赖关系的原因,包版本根本就不存在 .

    看起来您的项目文件更新在某些时候失败,并将Kotlin版本设置为1.0.7 . 如果这是一个新项目,并且没有什么阻止你使用1.1.1,我会切换到那个 . 这样做之后你的问题就应该消失了 .

  • 19

    在“build.gradle”文件中,更改该行的当前Kotlin版本并按下synk:

    ext.kotlin_version = '1.1.1'
    

    ///看起来像:

    //顶级构建文件,您可以在其中添加所有子项目/模块共有的配置选项 .

    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
        }
    }
    
  • 1

    从Kotlin 1.1.2开始,默认情况下使用从应用插件中获取的版本来解析与组 org.jetbrains.kotlin 的依赖关系 . 您可以使用完整的依赖项表示法手动提供版本,例如:

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

    如果您的目标是JDK 7或JDK 8,则可以使用Kotlin标准库的扩展版本,其中包含在新JDK版本中添加的API的其他扩展功能 . 而不是kotlin-stdlib,使用以下依赖项之一:

    compile "org.jetbrains.kotlin:kotlin-stdlib-jdk7"
    compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
    
  • 0
    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()`enter code here`enter code here`
            maven { url "https://jitpack.io" }
        }
    }
    
  • 6

    如果您使用Android Studio 3.2的新解决方案,我通过将mavenCentral()添加到项目的build.gradle来解决此问题:

    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()
        }
    }
    

    您应该将该行添加为此订单,贷记的是this answer

  • 84
    • 请在下面的路径中查看您的Kotlin的当前版本,

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

    在项目级gradle文件中更改为该版本 (1.0.5) .

    你可以在上面的路径中看到没有提到任何Java - jre version ,所以在你的app level gradle文件中删除如下,

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

    这对我有用:使用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/'
        }
      }
    }
    
  • 10

    https://stackoverflow.com/a/44148210/8056898

    根据您当前的系统版本更改Kotlin版本 .

  • 4

    我在 Settings 中取消选择 Offline work 选项解决了这个问题

    enter image description here

  • 0

    如果(传递)依赖关系仍然使用Kotlin库的 jre 变体,您可以在解决策略的帮助下强制使用 jdk 变体:

    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'.")
                    }
                }
            }
        }
    }
    
  • 0

    如果您使用的是Android Studio 3.2及更高版本,则可以通过将google()和jcenter()添加到项目的build.gradle来解决问题:

    repositories {
            google()
            jcenter()
    }
    
  • 1

    更换

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

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

相关问题