Bootstrap

Android studio中通过Gradle依赖无法下载三方库Failed to resolve: com.scwang.smartrefresh:SmartRefreshLayout:1.1.0

前些天发现了一个蛮有意思的人工智能学习网站,8个字形容一下"通俗易懂,风趣幽默",感觉非常有意思,忍不住分享一下给大家。
👉点击跳转到教程

前言:
在老版本Android studio中已经在build.gradle中配置了国内镜像源/依赖库

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
    ext.kotlin_version = "1.4.32"
    repositories {
        google()
        jcenter()
        maven { url 'https://jitpack.io' }
        maven { url 'https://maven.aliyun.com/repository/releases' }
        maven { url 'https://maven.aliyun.com/repository/jcenter' }
        maven { url 'https://maven.aliyun.com/repository/google' }
        maven { url 'https://maven.aliyun.com/repository/central' }
        maven { url 'https://maven.aliyun.com/repository/gradle-plugin' }
        maven { url 'https://maven.aliyun.com/repository/public' }
    }
    dependencies {
        classpath "com.android.tools.build:gradle:4.1.3"
        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()
        maven { url 'https://jitpack.io' }
        maven { url 'https://maven.aliyun.com/repository/releases' }
        maven { url 'https://maven.aliyun.com/repository/jcenter' }
        maven { url 'https://maven.aliyun.com/repository/google' }
        maven { url 'https://maven.aliyun.com/repository/central' }
        maven { url 'https://maven.aliyun.com/repository/gradle-plugin' }
        maven { url 'https://maven.aliyun.com/repository/public' }
    }
}

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

在新版中Android studio中这里是2023.2.1版本的setting.gradle中配置了国内镜像源/依赖库

pluginManagement {
    repositories {
        google {
            content {
                includeGroupByRegex("com\\.android.*")
                includeGroupByRegex("com\\.google.*")
                includeGroupByRegex("androidx.*")
            }
        }
        mavenCentral()
        gradlePluginPortal()
        maven { url = uri("https://www.jitpack.io") }
        maven { url=uri ("https://www.jitpack.io")}
        maven { url=uri ("https://maven.aliyun.com/repository/releases")}
        maven { url=uri ("https://maven.aliyun.com/repository/google")}
        maven { url=uri ("https://maven.aliyun.com/repository/central")}
        maven { url=uri ("https://maven.aliyun.com/repository/gradle-plugin")}
        maven { url=uri ("https://maven.aliyun.com/repository/public")}
    }
}
dependencyResolutionManagement {
    RepositoriesMode,包含三个取值:
    1.  PREFER_PROJECT:表示优先使用当前项目中指定的仓库。
    2.  PREFER_SETTINGS:表示优先使用在 Gradle 设置文件 (settings.gradle) 中指定的仓库。
    3.  FAIL_ON_PROJECT_REPOS:表示只使用明确声明的仓库,不允许使用当前项目的仓库。
     这个枚举类型被标记为 @Incubating,表示这是一个孵化阶段的功能,在将来版本中可能会有所变化。
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        google()
        mavenCentral()
        maven { url = uri("https://www.jitpack.io") }
        maven { url=uri ("https://www.jitpack.io")}
        maven { url=uri ("https://maven.aliyun.com/repository/releases")}
        maven { url=uri ("https://maven.aliyun.com/repository/google")}
        maven { url=uri ("https://maven.aliyun.com/repository/central")}
        maven { url=uri ("https://maven.aliyun.com/repository/gradle-plugin")}
        maven { url=uri ("https://maven.aliyun.com/repository/public")}
    }
}

rootProject.name = "AndroidLearnNew"
include ':app'

以上这些都配置了,某些库依旧下载不下来,并不是全部的。
比如Failed to resolve: com.scwang.smartrefresh:SmartRefreshLayout:1.1.0
在这里插入图片描述
最后解决在找到gradle下载gradle版本文件的地址如下图所示:
在这里插入图片描述
找到对应的文件目录把init.gradle和gradle.properties文件删除即可。这两个文件默认应该是没有的,后期自己加的文件,可能会导致某些下载不下来,删除就可以了。

共勉:

比你命运更糟糕的人还在奋斗,你有什么理由不坚持!!!

悦读

道可道,非常道;名可名,非常名。 无名,天地之始,有名,万物之母。 故常无欲,以观其妙,常有欲,以观其徼。 此两者,同出而异名,同谓之玄,玄之又玄,众妙之门。

;