136

I recently updated my android studio to Arctic Fox and got an error in my project

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. 

This is my gradle where the problem occurs

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() } 

How do I solve it?

4
  • 2
    Add allowInsecureProtocol = true for all unsecure http in repositories Commented Oct 27, 2021 at 4:05
  • What does "This is my gradle" mean? build.gradle? Commented Jan 5, 2023 at 13:59
  • @TheincredibleJan build.gradle Commented Jan 7, 2023 at 10:16
  • @AshrafAmin Yeah, the Gradle documentation says that too. But the page this message directs you to doesn't give the slightest indication where you need to do that. Commented Apr 9, 2023 at 13:09

8 Answers 8

270

For insecure HTTP connections in Gradle 7+ versions, we need to specify a boolean allowInsecureProtocol as true to MavenArtifactRepository closure.
Since you have received this error for sonatype repository, you need to set the repositories as below:

  1. Groovy DSL
repositories { maven { url "http://oss.sonatype.org/content/repositories/snapshots" allowInsecureProtocol = true } // other repositories ... } 
  1. Kotlin DSL
repositories { maven { url = uri("http://oss.sonatype.org/content/repositories/snapshots") isAllowInsecureProtocol = true } // other repositories ... } 
Sign up to request clarification or add additional context in comments.

8 Comments

What is the syntax for configuring both url and allowInsecureProtocol on the same line?
Well, that's Groovy, so you could separate the statements using ; if you want them to be on the same line.
Add allowInsecureProtocol = true for all unsecure http in repositories
My problem got solved by adding allowInsecureProtocol = true in my (Windows) C:\Users\<userid>\.gradle\init.gradle file
You now need to use it as allowInsecureProtocol(true)
|
50

or you can just replace HTTP with HTTPS.

4 Comments

Maybe you can't if you use your own mirror that doesn't support SSL.
Not just like that, you'll need a trusted certificate.
It worked trying this and with a single letter "S" :)
It's not always the best solution, as if you have vpn for example it will slow down the build significantly
28

For those using the Kotlin DSL, the property name is different isAllowInsecureProtocol

maven { url = uri("http://oss.sonatype.org/content/repositories/snapshots") isAllowInsecureProtocol = true } 

Comments

14

Note that Gradle 7 onwards, any insecure URL is blocked, not only for repositories, so applying scripts would also fail.

apply from: "http://mycompany.com/buildscript.gradle" 

Applying script plugins from insecure URIs, without explicit opt-in, is unsupported.

If you can't use HTTPS for whatever reasons, then do the following:

apply from: resources.text.fromInsecureUri("http://mycompany.com/buildscript.gradle") 

However, if I were a Gradle dev, I'd provide a org.gradle.allow-insecure-protocol=true to be set in the gradle.properties and be done. I've opened https://github.com/gradle/gradle/issues/18006 for that.

Comments

13

Add allowInsecureProtocol = true for all unsecure http in repositories e.g.

maven { url "http://storage.googleapis.com/r8-releases/raw" allowInsecureProtocol = true } maven { url "http://tokbox.bintray.com/maven/" allowInsecureProtocol = true } 

Comments

9

For me, coding the assignment statement "allowInsecureProtocol = true" stopped working** in a recent workspace using Gradle 7.x (the reason as yet, is unknown.) I found that when I instead coded setAllowInsecureProtocol(true) and it was OK again.

 maven { url "http://myinsecure/repository..."; setAllowInsecureProtocol(true); // allowInsecureProtocol = true } 

I have no info about exactly when the assignment statement stopped working.

Also, regarding comments about using https instead - I get it - it's good advice, but in this instance that is out of my control.

** referring to the build.gradle ...maven clauses

3 Comments

I am also facing the same issue but in my case setAllowInsecureProtocol(true); this is also not working
Greetings! @Shubham - would you please clarify for me : Have you also tried using the assignment form " allowInsecureProtool = true " and that was also failing? also which Gradle version number are you on?
Thanks @pete for reply. The issue is now fixed. Need to use allowInsecureProtocol = true in Publishing as well. Thanks
1

I solved this problem,by change my gradle version.Because my project need gradle version is lower than the Android Studio given.

1 Comment

Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
-2

I tried to switch to maven2 solved my problem

 maven2 { url "http://oss.sonatype.org/content/repositories/snapshots" allowInsecureProtocol = true } 

1 Comment

No candidates found for method call maven2.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.