Allow Insecure Protocols, Android Gradle

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()' to redirect to a secure protocol (like HTTPS) or allow insecure protocols.
 See  for more details. 

This is my gradle where the problem occurs

repositories {
    // maven { url ' }
    maven { url "" }
    maven { url ' }
    maven { url '
    maven { url "" }
    maven { url '  }
    google()
    mavenCentral()
    jcenter()
}

How do I solve it?

4

8 Answers

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 ""
        allowInsecureProtocol = true
    }
    // other repositories ...
}
  1. Kotlin DSL
repositories {
    maven {
        url = uri("")
        isAllowInsecureProtocol = true
    }
    // other repositories ...
}
8

or you can just replace HTTP with HTTPS.

4

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

maven {
    url = uri("")
    isAllowInsecureProtocol = true
}
0

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

apply from: ""

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

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 for that.

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

maven {
        url ""
        allowInsecureProtocol = true
    }

maven {
        url ""
        allowInsecureProtocol = true
    }

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 ""; 
            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

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

1

I tried to switch to maven2 solved my problem

 maven2 {
            url ""
            allowInsecureProtocol = true
        }
1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Sarah Jenkins

Sarah Jenkins

Senior Technology Editor & AI Specialist

Sarah Jenkins is a veteran tech journalist with over 12 years of experience covering artificial intelligence, mobile innovations, and digital ethics. Her insights have appeared in leading technology publications worldwide.

Share this article
Twitter Facebook Pinterest