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

Android Studio编译失败:无法找到semver4j-0.16.4-nodeps.jar依赖

Gradle编译失败:无法找到semver4j-0.16.4-nodeps.jar

编译时出现如下错误:

A problem occurred configuring root project 'PingTv - Copy'.
> Could not resolve all files for configuration ':classpath'.
   > Could not find semver4j-0.16.4-nodeps.jar (com.github.gundy:semver4j:0.16.4).
     Searched in the following locations:
         https://jitpack.io/com/github/gundy/semver4j/0.16.4/semver4j-0.16.4-nodeps.jar

Possible solution:
 - Declare repository providing the artifact, see the documentation at https://docs.gradle.org/current/userguide/declaring_repositories.html

我试过相关问题的解决方案,但没有效果,希望能得到解决办法。以下是我的项目根目录下的build.gradle文件内容:

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

buildscript {
    ext.kotlin_version = '1.7.10'
    repositories {
        maven {
            url "https://jitpack.io"
        }
        maven {
            url "http://oss.sonatype.org/content/repositories/snapshots"
            allowInsecureProtocol = true
        }
        maven {
            url "https://plugins.gradle.org/m2/"
        }
        maven {
            url "https://maven.google.com"
        }
        mavenCentral()
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:7.3.0'
        classpath 'com.google.gms:google-services:4.3.14'
        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 {
    configurations {
        all {
            exclude group: 'androidx.lifecycle', module: 'lifecycle-viewmodel-ktx'
        }
    }
    repositories {
        google()
        mavenCentral()

        maven {
            url 'https://jitpack.io'
        }
        maven {
            url 'https://mvnrepository.com/artifact/com.github.gundy/semver4j' //-> Add
        }

        maven {
            url "https://dl.appnext.com/"
        }
        maven {
            url 'https://startappdev.bintray.com/maven'
        }
        maven {
            url "http://oss.sonatype.org/content/repositories/snapshots"
            allowInsecureProtocol = true
        }
        maven {
            url "https://plugins.gradle.org/m2/"
        }
        maven {
            url "https://maven.google.com"
        }
        flatDir {
            dirs 'libs'
        }
    }
}

可行的解决办法

1. 修正无效的仓库地址

你添加的https://mvnrepository.com/artifact/com.github.gundy/semver4j不是有效的Maven仓库,mvnrepository只是依赖查询网站,不能用来拉取依赖。直接删除这个仓库配置。

2. 调整buildscript的仓库顺序

错误出现在classpath配置(即buildscript块的依赖),所以要确保buildscript的仓库能优先找到该依赖。修改buildscript的repositories部分:

buildscript {
    ext.kotlin_version = '1.7.10'
    repositories {
        mavenCentral()
        google()
        maven { url "https://jitpack.io" } // 优先加载JitPack
        maven {
            url "http://oss.sonatype.org/content/repositories/snapshots"
            allowInsecureProtocol = true
        }
        maven { url "https://plugins.gradle.org/m2/" }
        maven { url "https://maven.google.com" }
        jcenter() // JCenter已废弃,建议直接移除
    }
    dependencies {
        // 依赖保持不变
        classpath 'com.android.tools.build:gradle:7.3.0'
        classpath 'com.google.gms:google-services:4.3.14'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
    }
}

3. 更换semver4j版本或手动引入jar包

如果JitPack上的0.16.4版本构建失败导致包缺失,可以尝试降级到Maven Central上存在的0.16.3版本,或者手动下载semver4j-0.16.4-nodeps.jar放到项目的libs目录,然后在buildscript中添加本地依赖:

buildscript {
    repositories {
        // 其他仓库...
        flatDir { dirs 'libs' }
    }
    dependencies {
        // 其他依赖...
        classpath files('libs/semver4j-0.16.4-nodeps.jar')
    }
}

4. 清理Gradle缓存

执行以下命令清理本地缓存并重新构建:

./gradlew clean build --refresh-dependencies

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.17 02:55:30