Android Studio 找不到 Kotlin 依赖项
Posted
技术标签:
【中文标题】Android Studio 找不到 Kotlin 依赖项【英文标题】:Android Studio can't find Kotlin dependency 【发布时间】:2020-07-16 10:50:30 【问题描述】:我正在尝试为我的 android Studio 项目升级一些依赖项,现在每当我尝试构建项目时都会遇到此错误消息:
Could not determine the dependencies of task ':app:compileDebugJavaWithJavac'.
> Could not resolve all task dependencies for configuration ':app:debugAnnotationProcessorClasspath'.
> Could not find org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.3.60-eap-25.
Searched in the following locations:
- https://dl.google.com/dl/android/maven2/org/jetbrains/kotlin/kotlin-stdlib-jdk8/1.3.60-eap-25/kotlin-stdlib-jdk8-1.3.60-eap-25.pom
- https://jcenter.bintray.com/org/jetbrains/kotlin/kotlin-stdlib-jdk8/1.3.60-eap-25/kotlin-stdlib-jdk8-1.3.60-eap-25.pom
Required by:
project :app > androidx.databinding:databinding-compiler:4.0.0-alpha04
project :app > androidx.databinding:databinding-compiler:4.0.0-alpha04 > androidx.databinding:databinding-compiler-common:4.0.0-alpha04
这是我的项目 gradle 文件:
buildscript
// Define versions in a single place
ext
// Sdk and tools
compileSdkVersion = 28
minSdkVersion = 21
targetSdkVersion = 28
// App dependencies
appCompatVersion = '1.1.0'
fragmentVersion = '1.2.3'
gradleVersion = '4.0.0-alpha04'
kotlinVersion = '1.3.60-eap-25'
ktlintVersion = '0.33.0'
ktxVersion = '1.2.0'
mapVersion = '17.0.0'
repositories
google()
jcenter()
mavenCentral()
maven url 'https://dl.bintray.com/kotlin/kotlin-eap'
dependencies
classpath "com.android.tools.build:gradle:$gradleVersion"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$navigationVersion"
plugins
id "com.diffplug.gradle.spotless" version "3.24.0"
allprojects
repositories
google()
jcenter()
spotless
kotlin
target "**/*.kt"
ktlint(ktlintVersion).userData(['max_line_length' : '100'])
以及相关的app gradle依赖:
kaptTest "androidx.databinding:databinding-compiler:$gradleVersion"
implementation "androidx.core:core-ktx:$rootProject.ktxVersion"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$rootProject.kotlinVersion"
我尝试过使用其他 Kotlin 版本,但这样做时我什至无法同步 gradle 文件。
【问题讨论】:
【参考方案1】:试试这个:
build.gradle(:app)
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
android
compileSdkVersion 29
buildToolsVersion "29.0.3"
defaultConfig
applicationId "com.example.mytestapplication"
minSdkVersion 21
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
buildTypes
release
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
dependencies
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.google.android.material:material:1.1.0'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
implementation 'androidx.core:core:1.3.0-alpha02'
implementation 'androidx.mediarouter:mediarouter:1.1.0'
build.gradle(:projectname)
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript
ext.kotlin_version = '1.3.61'
repositories
google()
jcenter()
dependencies
classpath 'com.android.tools.build:gradle:3.6.1'
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
allprojects
repositories
google()
jcenter()
task clean(type: Delete)
delete rootProject.buildDir
【讨论】:
以上是关于Android Studio 找不到 Kotlin 依赖项的主要内容,如果未能解决你的问题,请参考以下文章
找不到类,使用 Android Studio 3.0.1、Room、Kotlin 的 androidTest 中的空测试套件
如何在 Kotlin 中创建一个打开新活动(Android Studio)的按钮?
如何在 Android Studio 中使用 Kotlin 处理 WebChromeClient 中的输入类型文件?