允许不安全的协议,android gradle
Allow insecure protocols, android gradle
我最近将我的 android 工作室更新为 Arctic Fox,但我的项目出现错误
A problem occurred configuring root project 'so10'.
> Could not resolve all dependencies for configuration ':classpath'.
> Using insecure protocols with repositories, without explicit opt-in, is unsupported. Switch Maven repository
'maven3(http://oss.sonatype.org/content/repositories/snapshots)' to redirect to a secure protocol (like HTTPS) or allow insecure protocols.
See https://docs.gradle.org/7.0.2/dsl/org.gradle.api.artifacts.repositories.UrlArtifactRepository.html#org.gradle.api.artifacts.repositories.UrlArtifactRepository:allowInsecureProtocol for more details.
这是我的gradle出现问题的地方
repositories {
// maven { url 'https://maven.fabric.io/public' }
maven { url "https://jitpack.io" }
maven { url 'https://raw.github.com/Raizlabs/maven-releases/master/releases' }
maven { url 'http://oss.sonatype.org/content/repositories/snapshots'}
maven { url "https://plugins.gradle.org/m2/" }
maven { url 'https://maven.google.com' }
google()
mavenCentral()
jcenter()
}
如何解决?
对于 Gradle 7+ 版本中的不安全 HTTP 连接,我们需要将布尔值 allowInsecureProtocol 指定为 MavenArtifactRepository
闭包。
由于您收到 sonatype
存储库的此错误,您需要按如下方式设置存储库:
- Groovy DSL
repositories {
maven {
url "http://oss.sonatype.org/content/repositories/snapshots"
allowInsecureProtocol = true
}
// other repositories ...
}
- Kotlin DSL
repositories {
maven {
url = uri("http://oss.sonatype.org/content/repositories/snapshots")
isAllowInsecureProtocol = true
}
// other repositories ...
}
或者您可以将 HTTP
替换为 HTTPS
。
请注意,Gradle 7 之后,任何 不安全的 URL 都被阻止,不仅对于存储库,因此应用脚本也会失败。
apply from: "http://mycompany.com/buildscript.gradle"
Applying script plugins from insecure URIs, without explicit opt-in, is unsupported.
如果您出于某种原因无法使用 HTTPS,请执行以下操作:
apply from: resources.text.fromInsecureUri("http://mycompany.com/buildscript.gradle")
但是,如果我是 Gradle 开发人员,我会提供 org.gradle.allow-insecure-protocol=true
以在 gradle.properties
中设置并完成。我为此打开了https://github.com/gradle/gradle/issues/18006。
对于使用 Kotlin DSL 的用户,属性 名称不同 isAllowInsecureProtocol
maven {
url = uri("http://oss.sonatype.org/content/repositories/snapshots")
isAllowInsecureProtocol = true
}
为存储库中的所有不安全 http 添加 allowInsecureProtocol = true,例如
maven {
url "http://storage.googleapis.com/r8-releases/raw"
allowInsecureProtocol = true
}
maven {
url "http://tokbox.bintray.com/maven/"
allowInsecureProtocol = true
}
我最近将我的 android 工作室更新为 Arctic Fox,但我的项目出现错误
A problem occurred configuring root project 'so10'.
> Could not resolve all dependencies for configuration ':classpath'.
> Using insecure protocols with repositories, without explicit opt-in, is unsupported. Switch Maven repository
'maven3(http://oss.sonatype.org/content/repositories/snapshots)' to redirect to a secure protocol (like HTTPS) or allow insecure protocols.
See https://docs.gradle.org/7.0.2/dsl/org.gradle.api.artifacts.repositories.UrlArtifactRepository.html#org.gradle.api.artifacts.repositories.UrlArtifactRepository:allowInsecureProtocol for more details.
这是我的gradle出现问题的地方
repositories {
// maven { url 'https://maven.fabric.io/public' }
maven { url "https://jitpack.io" }
maven { url 'https://raw.github.com/Raizlabs/maven-releases/master/releases' }
maven { url 'http://oss.sonatype.org/content/repositories/snapshots'}
maven { url "https://plugins.gradle.org/m2/" }
maven { url 'https://maven.google.com' }
google()
mavenCentral()
jcenter()
}
如何解决?
对于 Gradle 7+ 版本中的不安全 HTTP 连接,我们需要将布尔值 allowInsecureProtocol 指定为 MavenArtifactRepository
闭包。
由于您收到 sonatype
存储库的此错误,您需要按如下方式设置存储库:
- Groovy DSL
repositories {
maven {
url "http://oss.sonatype.org/content/repositories/snapshots"
allowInsecureProtocol = true
}
// other repositories ...
}
- Kotlin DSL
repositories {
maven {
url = uri("http://oss.sonatype.org/content/repositories/snapshots")
isAllowInsecureProtocol = true
}
// other repositories ...
}
或者您可以将 HTTP
替换为 HTTPS
。
请注意,Gradle 7 之后,任何 不安全的 URL 都被阻止,不仅对于存储库,因此应用脚本也会失败。
apply from: "http://mycompany.com/buildscript.gradle"
Applying script plugins from insecure URIs, without explicit opt-in, is unsupported.
如果您出于某种原因无法使用 HTTPS,请执行以下操作:
apply from: resources.text.fromInsecureUri("http://mycompany.com/buildscript.gradle")
但是,如果我是 Gradle 开发人员,我会提供 org.gradle.allow-insecure-protocol=true
以在 gradle.properties
中设置并完成。我为此打开了https://github.com/gradle/gradle/issues/18006。
对于使用 Kotlin DSL 的用户,属性 名称不同 isAllowInsecureProtocol
maven {
url = uri("http://oss.sonatype.org/content/repositories/snapshots")
isAllowInsecureProtocol = true
}
为存储库中的所有不安全 http 添加 allowInsecureProtocol = true,例如
maven {
url "http://storage.googleapis.com/r8-releases/raw"
allowInsecureProtocol = true
}
maven {
url "http://tokbox.bintray.com/maven/"
allowInsecureProtocol = true
}