本文介绍了Android Studio在第二次构建后显示Kotlin依赖警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我刚刚在我的Android项目中启用了Kotlin,但偶然发现了一个警告.在第二次构建(构建->重建项目)之后,此警告显示在消息下:Warning:Runtime JAR files in the classpath should have the same version. These files were found in the classpath:~/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-jdk8/1.2.10/85fe1811f3e586d0cc53aba1394d8089f1862215/kotlin-stdlib-jdk8-1.2.10.jar (version 1.2)~/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-reflect/1.2.10/19bc012f8c4cd6b705bd6512263777cc19bcf259/kotlin-reflect-1.2.10.jar (version 1.2)/Applications/Android Studio.app/Contents/gradle/m2repository/org/jetbrains/kotlin/kotlin-stdlib-jre7/1.1.51/kotlin-stdlib-jre7-1.1.51.jar (version 1.1)~/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-jdk7/1.2.10/cfe8b616b3bf0811ef70863c86b745a2e767a66e/kotlin-stdlib-jdk7-1.2.10.jar (version 1.2)~/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib/1.2.10/b9bf650516989595a5390e5a54181e16347208ac/kotlin-stdlib-1.2.10.jar (version 1.2)似乎第二个版本包含来自缓存的过时的kotlin-stdlib-jre7-1.1.51.jar.进行完干净的构建(Build-> Clean Project)后,警告消失了,下一个Rebuild Project再次将其显示.我正在使用Android Studio 3.0.1,并且在版本中明确包括了Kotlin依赖项: build.gradle buildscript { ext { // shared build properties kotlin_version = '1.2.10' buildToolsVersion = '27.0.2' minSdkVersion = 15 targetSdkVersion = 27 compileSdkVersion = 27 } repositories { jcenter() google() } dependencies { classpath "com.android.tools.build:gradle:3.0.1" classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${kotlin_version}" }} app/build.gradle apply plugin: 'com.android.application'apply plugin: 'kotlin-android'apply plugin: 'kotlin-kapt'dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:${kotlin_version}" implementation "org.jetbrains.kotlin:kotlin-reflect:${kotlin_version}" [...]}还在我们的 travis构建上,显示了警告.因此,这不仅是我的本地设置的问题.即使只是警告,发布包含冲突版本的apk也让我感到不舒服.解决方案 摘要 您已经解决了更新依赖关系的问题,但我将在此处回答以链接相关问题. 您已正确配置了项目依赖项,并将Kotlin插件更新为1.2. 这通常就足够了,就像此处一样,但是在Kotlin 1.2中,stdlib-jre依赖项已更改为jdk. /p> 但是您的项目取决于Realm版本4.3.1,他们在版本4.3.2.中对此进行了修复. 您可以通过命令或AS 3.1中的新构建选项卡找到导致问题的依赖项. 1.添加显式依赖项并更新依赖项 文档中介绍了Kotlin标准库的扩展版本. >和此答案. 如果自动解析不能正常工作,请更新其他依赖项(请参阅第5点). 2.配置Gradle和Kotlin插件更新修改您的Gradle配置.为了构建用Kotlin编写的Android项目:设置kotlin-android gradle插件并将其应用于您的项目.添加kotlin-stdlib依赖项. 3.在1.2.x版本中,将kotlin-stdlib-jre7重命名为kotlin-stdlib-jdk7 4. Realm已在4.3.2版本中更新为Kotlin 1.2 5.通过命令查找冲突的依赖项,或者从AS 3.1开始构建选项卡./gradlew -q dependencies app:dependencies --configuration variantDebugCompileClasspath从Android Studio 3.1 Beta 1开始,您可以使用新的构建标签来找到冲突的依赖项:在这种情况下,您删除了警告,并修复了将Realm版本更新为4.3.2的问题:考虑下载了订单依存关系,也可以在Travis-ci版本中进行检查: I've just enabled Kotlin in my Android project and I stumbled upon a warning. After the second build (Build -> Rebuild Project) this warning is shown under Messages:Warning:Runtime JAR files in the classpath should have the same version. These files were found in the classpath:~/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-jdk8/1.2.10/85fe1811f3e586d0cc53aba1394d8089f1862215/kotlin-stdlib-jdk8-1.2.10.jar (version 1.2)~/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-reflect/1.2.10/19bc012f8c4cd6b705bd6512263777cc19bcf259/kotlin-reflect-1.2.10.jar (version 1.2)/Applications/Android Studio.app/Contents/gradle/m2repository/org/jetbrains/kotlin/kotlin-stdlib-jre7/1.1.51/kotlin-stdlib-jre7-1.1.51.jar (version 1.1)~/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib-jdk7/1.2.10/cfe8b616b3bf0811ef70863c86b745a2e767a66e/kotlin-stdlib-jdk7-1.2.10.jar (version 1.2)~/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib/1.2.10/b9bf650516989595a5390e5a54181e16347208ac/kotlin-stdlib-1.2.10.jar (version 1.2)It seems like the second build includes the outdated kotlin-stdlib-jre7-1.1.51.jar from cache. After a clean build (Build -> Clean Project) the warning is gone, and the next Rebuild Project brings it up again.I'm using Android Studio 3.0.1 and I explicitly include the Kotlin dependencies with version:build.gradlebuildscript { ext { // shared build properties kotlin_version = '1.2.10' buildToolsVersion = '27.0.2' minSdkVersion = 15 targetSdkVersion = 27 compileSdkVersion = 27 } repositories { jcenter() google() } dependencies { classpath "com.android.tools.build:gradle:3.0.1" classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${kotlin_version}" }}app/build.gradleapply plugin: 'com.android.application'apply plugin: 'kotlin-android'apply plugin: 'kotlin-kapt'dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:${kotlin_version}" implementation "org.jetbrains.kotlin:kotlin-reflect:${kotlin_version}" [...]}Also on our travis builds the warning is shown. Thus, it is not only a problem with my local setup. Even if it is only a warning, I don't feel comfortable by releasing an apk that includes conflicting versions. 解决方案 SummaryYou already fixed it updating your dependencies but I'll answer here to link a related question.You configured correctly your project dependencies and updated the Kotlin plugin to 1.2.This is normally enough like here but stdlib-jre dependencies were changed to jdk in Kotlin 1.2.But your project was depending on Realm version 4.3.1, and they fixed this in version 4.3.2.You can find the dependency causing the issue via commands or the new build tab in AS 3.1.1. Add explicit dependencies and update dependenciesExtended versions of the Kotlin standard library are explained in documentation and this answer.Update other dependencies, if the automatic resolution doesn't work properly (see point 5).2. Configure Gradle and Kotlin plugin updatesRevise your Gradle configuration. In order to to build an Android project written in Kotlin:Set up the kotlin-android gradle plugin and apply it to your project.Add kotlin-stdlib dependencies.3. kotlin-stdlib-jre7 renamed to kotlin-stdlib-jdk7 during the 1.2.x release4. Realm updated to Kotlin 1.2 in 4.3.2 version5. Find conflictive dependencies via command, or build tab since AS 3.1./gradlew -q dependencies app:dependencies --configuration variantDebugCompileClasspathSince Android Studio 3.1 Beta 1, you can use the new build tab to find the conflictive dependency:In this case, you removed the warning and fixed the issue updating Realm version to 4.3.2:It's also possible to check it in Travis-ci builds considering the order dependencies are downloaded: 这篇关于Android Studio在第二次构建后显示Kotlin依赖警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-03 20:31
查看更多