Use HTTP as default in IntelliJ or Android Studio

2019-02-19 11:42发布

问题:

I know this may seem like an odd request (which may help explain why no google research is helping me find the answer) but due to some firewall issues, connecting to external resources via HTTPS takes a very long time or times out entirely.

Currently my dependencies look like:

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:appcompat-v7:22.2.0'
    compile 'com.android.support:support-v4:22.2.0'
    compile 'com.squareup.picasso:picasso:2.5.2'
    compile 'com.google.code.gson:gson:2.3.1'
    compile 'com.mcxiaoke.volley:library:1.0.18'
}

And my error woes look like:

Error:A problem occurred configuring project ':app'.
> Could not resolve all dependencies for configuration ':app:_debugCompile'.
   > Could not resolve com.mcxiaoke.volley:library:1.0.18.
     Required by:
         udacity-android-nanodegree--july2015-project1:app:unspecified
      > Could not GET 'https://jcenter.bintray.com/com/mcxiaoke/volley/library/1.0.18/library-1.0.18.pom'.
         > Connection to https://jcenter.bintray.com refused
      > Could not GET 'https://repo1.maven.org/maven2/com/mcxiaoke/volley/library/1.0.18/library-1.0.18.pom'.
         > Connection to https://repo1.maven.org refused

Now, these errors come and go and really depend on the backbone firewall taking its time on the HTTPS requests. If you look close at the error, it references https://jcenter.bintray.com/com/mcxiaoke/volley/library/1.0.18/library-1.0.18.pom which, when you strip out the https and replace it with just http it reveals the same thing.

For connections that need to be secure, HTTPS due to security/logins/etc, its fine, but for downloading public libraries and dependencies, how do I ensure Android Studio sticks with regular HTTP?

回答1:

Hmm I think I found my answer. I just need to update my repositories instructions in my gradle script to force it to HTTP:

repositories {
    maven {
        url "http://repo1.maven.org/maven2"
    }
}

before it was just mavenCentral() which much have been HTTPS based