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

无法解析依赖com.github.glomadrian:MaterialAnimatedSwitch:1.1求助

搞定MaterialAnimatedSwitch依赖解析失败的问题

哥们,你遇到的ERROR: Failed to resolve: com.github.glomadrian:MaterialAnimatedSwitch:1.1报错,本质原因是你配置的Bintray仓库已经在2021年停止服务了,那个https//dl.bintray.com/glomadrian/maven地址现在完全访问不了,所以Gradle根本拉取不到依赖包。给你几个实用的解决方案:

方案一:改用JitPack仓库拉取(最推荐)

JitPack是专门托管GitHub项目依赖的仓库,这个组件的源码在GitHub上,所以可以通过JitPack来获取:

  1. 先根据你的Gradle版本配置JitPack仓库:
    • 如果你用的是Gradle 7.0+,打开项目根目录的settings.gradle,在dependencyResolutionManagement块里添加:
      dependencyResolutionManagement {
          repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
          repositories {
              google()
              mavenCentral()
              maven { url 'https://jitpack.io' } // 新增这一行
          }
      }
      
    • 如果你用的是旧版Gradle,打开根目录的build.gradle,在allprojects块里添加:
      allprojects {
          repositories {
              google()
              mavenCentral()
              maven { url 'https://jitpack.io' } // 新增这一行
          }
      }
      
  2. 然后回到App级的build.gradle,保持依赖写法不变(JitPack支持这种GitHub依赖格式):
    dependencies {
        implementation 'com.github.glomadrian:MaterialAnimatedSwitch:1.1'
    }
    
  3. 点击Sync Now同步Gradle,应该就能正常下载依赖了。

方案二:手动下载源码本地引入

如果JitPack也抽风,你可以直接把这个库的源码拉到本地作为Module引入:

  1. 去作者的GitHub仓库下载整个项目的源码
  2. 解压后,把里面的library文件夹复制到你的项目根目录下
  3. 打开settings.gradle,添加以下配置:
    include ':materialanimatedswitch'
    project(':materialanimatedswitch').projectDir = new File(rootProject.projectDir, 'library')
    
  4. 再到App级build.gradle里添加本地依赖:
    dependencies {
        implementation project(':materialanimatedswitch')
    }
    
  5. 同步Gradle后就能用了。

方案三:用官方组件替代(最稳定)

这个第三方库已经很久没维护了,如果你不想折腾,直接用Google官方的Material Design组件SwitchMaterial就行,功能类似还更稳定:

  1. 先确保你的项目引入了Material Components库:
    dependencies {
        implementation 'com.google.android.material:material:1.11.0' // 版本可以根据需求调整
    }
    
  2. 在布局文件里直接用SwitchMaterial:
    <com.google.android.material.switchmaterial.SwitchMaterial
        android:id="@+id/my_switch"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="开关示例"/>
    

内容的提问来源于stack exchange,提问作者MD.Asif Hossain Ribhu

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.14 07:06:17