Gradle之适配
项目信息:
compileSdk = 34
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
agp = "8.5.1"
在项目中加入http协议的Maven 源的话,报错,信息如下
Build file 'D:\code\demo\MyApplication\build.gradle.kts' line: 2Error resolving plugin [id: 'com.android.application', version: '8.5.1', apply: false]
> Could not resolve all dependencies for configuration 'detachedConfiguration1'.> Using insecure protocols with repositories, without explicit opt-in, is unsupported.* Try:
> Switch Maven repository 'maven(http://maven.aliyun.com/repository/google)' to redirect to a secure protocol (like HTTPS) or allow insecure protocols.
> For more information, please refer to https://docs.gradle.org/8.7/dsl/org.gradle.api.artifacts.repositories.UrlArtifactRepository.html#org.gradle.api.artifacts.repositories.UrlArtifactRepository:allowInsecureProtocol in the Gradle documentation.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
> Get more help at https://help.gradle.org.
方案一(不推荐,仅作为临时方案)
pluginManagement {repositories {maven {isAllowInsecureProtocol = trueurl = uri("http://maven.aliyun.com/repository/google")}google {content {includeGroupByRegex("com\\.android.*")includeGroupByRegex("com\\.google.*")includeGroupByRegex("androidx.*")}}mavenCentral()gradlePluginPortal()}
}
dependencyResolutionManagement {repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)repositories {google()mavenCentral()}
}rootProject.name = "MyApplication"
include(":app")
方案二(推荐)
maven {url = uri("http://some.repository.url") // <-- 问题在这里}
换成
maven {url = uri("https://some.repository.url") // <-- 将 http 改为 https}