You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Android项目引入Koin 3.4.3报错:Could not resolve io.insert-koin:koin-core:3.4.3

问题描述

引入Koin 3.4.3时构建失败,错误信息:

> Could not resolve all files for configuration ':app:debugRuntimeClasspath'.
   > Could not resolve io.insert-koin:koin-core:3.4.3.

同步Gradle后执行构建时触发该错误,相关配置如下:

版本配置(versions.gradle)

ext.kotlin_version = '1.4.20'
ext.koinVersion = '3.4.3'
ext.appcompatVersion = '1.3.1'
ext.materialVersion = '1.4.0'
ext.constraintlayoutVersion = '2.0.4'
ext.coreKtxVersion = '1.6.0'
ext.multiDexVersion = '2.0.1'
ext.targetSdkVersion = 31
ext.compileSdkVersion = 31
ext.buildToolsVersion = '31.0.0'
ext.retrofitVersion = '2.9.0'
ext.okHttpInterceptorVersion = '4.10.0'
ext.recyclerviewVersion = '1.2.1'
ext.junitVersion = '4.13.1'
ext.junitAndroidxExtVersion = '1.1.3'
ext.junitAndroidxCoreVersion = '1.4.0'
ext.junitAndroidxExtKtxVersion = '1.1.3'
ext.testRunnerVersion = '1.4.0'
ext.testCoreKtxVersion = '1.4.0'

项目级build.gradle

buildscript {
    apply from: 'versions.gradle'
    repositories {
        mavenLocal()
        google()
        mavenCentral()
        maven { url 'https://maven.google.com' }
        maven { url 'https://jitpack.io' }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:7.1.0'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.6.10"
        classpath "io.insert-koin:koin-gradle-plugin:$koinVersion"
    }
}

allprojects {
    repositories {
        mavenLocal()
        google()
        maven { url 'https://maven.google.com' }
        maven { url 'https://jitpack.io' }
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

应用级build.gradle

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

android {
    compileSdkVersion 31

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    kotlinOptions {
        jvmTarget = JavaVersion.VERSION_1_8.toString()
    }

    signingConfigs {
        release {
            storeFile file("keystore.debug")
        }
    }

    defaultConfig {
        multiDexEnabled true
        applicationId "com.xxx"
        minSdkVersion 23
        targetSdkVersion 31
        versionCode 1
        versionName "1.0"
        signingConfig signingConfigs.release
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    packagingOptions {
        resources {
            excludes += ['META-INF/*.kotlin_module']
        }
    }
}

dependencies {
    androidTestImplementation "junit:junit:$junitVersion"
    androidTestImplementation "androidx.test.ext:junit:$junitAndroidxExtVersion"
    androidTestImplementation "androidx.test:core-ktx:$junitAndroidxCoreVersion"
    androidTestImplementation "androidx.test.ext:junit-ktx:$junitAndroidxExtKtxVersion"
    androidTestImplementation "androidx.test:runner:$testRunnerVersion"
    androidTestImplementation "androidx.test:core-ktx:$testCoreKtxVersion"

    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
    implementation "androidx.core:core-ktx:$coreKtxVersion"
    implementation "androidx.constraintlayout:constraintlayout:$constraintlayoutVersion"
    implementation "androidx.appcompat:appcompat:$appcompatVersion"
    implementation "androidx.multidex:multidex:$multiDexVersion"
    implementation "androidx.recyclerview:recyclerview:$recyclerviewVersion"
    implementation "com.google.android.material:material:$materialVersion"
    implementation "io.insert-koin:koin-android:$koinVersion"
    api "io.insert-koin:koin-core:$koinVersion"

    //Retrofit
    implementation "com.squareup.retrofit2:retrofit:$retrofitVersion"
    implementation "com.squareup.retrofit2:converter-gson:$retrofitVersion"
    implementation "com.squareup.okhttp3:logging-interceptor:$okHttpInterceptorVersion"
}
解决方案

问题出在三个关键点,逐个修正即可:

  • 仓库缺失mavenCentral
    Koin 3.x版本发布在mavenCentral上,但你的allprojects块里没添加这个仓库,导致Gradle找不到依赖。修改项目级build.gradle的allprojects部分:

    allprojects {
        repositories {
            mavenLocal()
            google()
            mavenCentral() // 新增这一行
            maven { url 'https://maven.google.com' }
            maven { url 'https://jitpack.io' }
        }
    }
    
  • Kotlin版本不兼容
    Koin 3.4.3要求Kotlin版本至少为1.7.20,但你配置的kotlin_version是1.4.20,同时gradle插件版本和Kotlin版本不匹配,直接导致依赖解析失败。需要:

    1. 修改versions.gradle里的kotlin_version为'1.7.20'(或更高兼容版本)
    2. 同步gradle插件版本,项目级build.gradle里的kotlin-gradle-plugin版本和kotlin_version保持一致:
      classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
      
  • 冗余依赖可移除
    koin-android已经默认依赖了koin-core,不需要单独声明api "io.insert-koin:koin-core:$koinVersion",删掉这一行可以避免重复依赖。


内容的提问来源于stack exchange,提问作者Nicote Ool

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.13 16:43:11