首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Gradle同步失败:不支持在存储库中使用不安全的协议,没有显式的选择。开关Maven存储库

Gradle同步失败:不支持在存储库中使用不安全的协议,没有显式的选择。开关Maven存储库
EN

Stack Overflow用户
提问于 2021-11-13 14:12:38
回答 1查看 4.7K关注 0票数 4

每当我打开android工作室时,Gradle同步都会失败。这是我的gradle.build文件。谁能告诉我怎么解决这个问题吗?我安装了7.2级。但我不知道是什么导致了这个问题..。我甚至尝试过allowInsecureProtocol = true

gradle.build/android

代码语言:javascript
运行
复制
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    ext {
        buildToolsVersion = "29.0.3"
        minSdkVersion = 21
        compileSdkVersion = 30
        targetSdkVersion = 30
        googlePlayServicesAuthVersion="16.0.1"
    }
    repositories {
        
        google()
        mavenCentral(){
        allowInsecureProtocol = true
    }
        maven{
             url 'https://maven.google.com/'
            name 'Google'
             
        }
    }
    dependencies {
        classpath 'com.google.gms:google-services:4.3.3'
        classpath("com.android.tools.build:gradle:4.2.0")

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
         google()
        mavenCentral(){
        allowInsecureProtocol = true
    }
        mavenLocal()
        maven {
            // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
            url("$rootDir/../node_modules/react-native/android")
             
            
        }
        maven {
            // Android JSC is installed from npm
            url("$rootDir/../node_modules/jsc-android/dist")
             
        }

        google()
        mavenCentral(){
        allowInsecureProtocol = true
    }
              
        maven { url 'https://www.jitpack.io' }
        
        
    }
}

gradle.build/app

代码语言:javascript
运行
复制
buildscript {


    
    repositories {
        google()
    mavenCentral(){
        allowInsecureProtocol = true
    }

    
   
    maven { url "https://plugins.gradle.org/m2/" }
    maven { url "http://repo1.maven.org/maven2" }
    maven { url "https://jitpack.io" }

    }
    dependencies {
        classpath 'com.android.tools.build:gradle:7.2'
        classpath 'com.google.gms:google-services:4.3.10'
        
    }
}

allprojects {
    repositories {
        mavenCentral()
        google()
        mavenCentral(){
        allowInsecureProtocol = true
    }
    }
}

apply plugin: 'com.android.library'

def safeExtGet(prop, fallback) {
    rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
}

android {
    compileSdkVersion safeExtGet('compileSdkVersion', 28)
    buildToolsVersion safeExtGet('buildToolsVersion', '28.0.3')

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    defaultConfig {
        minSdkVersion safeExtGet('minSdkVersion', 16)
        targetSdkVersion safeExtGet('targetSdkVersion', 28)
        versionCode 1
        versionName "1.0"
        ndk {
            abiFilters "armeabi-v7a", "x86"
        }
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    // Use either AndroidX library names or old/support library names based on major version of support lib
    def supportLibVersion = safeExtGet('supportLibVersion', '27.1.1')
    def supportLibMajorVersion = supportLibVersion.split('\\.')[0] as int
    def appCompatLibName =  (supportLibMajorVersion < 20) ? "androidx.appcompat:appcompat" : "com.android.support:appcompat-v7"

    implementation fileTree(dir: 'libs', include: ['*.jar'])
    testImplementation 'junit:junit:4.12'
    implementation "$appCompatLibName:$supportLibVersion"
    implementation 'com.facebook.react:react-native:+'
    implementation 'me.leolin:ShortcutBadger:1.1.22@aar'
    implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.0.0'
    implementation "com.google.firebase:firebase-messaging:${safeExtGet('firebaseMessagingVersion', '21.1.0')}"

}

,这是我得到的错误

代码语言:javascript
运行
复制
A problem occurred configuring root project 'RentInCars'.
> Could not resolve all dependencies for configuration ':classpath'.
   > Using insecure protocols with repositories, without explicit opt-in, is unsupported. Switch Maven repository 'BintrayJCenter2(http://jcenter.bintray.com/)' to redirect to a secure protocol (like HTTPS) or allow insecure protocols. See https://docs.gradle.org/7.2/dsl/org.gradle.api.artifacts.repositories.UrlArtifactRepository.html#org.gradle.api.artifacts.repositories.UrlArtifactRepository:allowInsecureProtocol for more details. 

* Try:
Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Exception is:
org.gradle.api.ProjectConfigurationException: A problem occurred configuring root project 'RentInCars'.
    at org.gradle.configuration.project.LifecycleProjectEvaluator.wrapException(LifecycleProjectEvaluator.java:75)
    at org.gradle.configuration.project.LifecycleProjectEvaluator.addConfigurationFailure(LifecycleProjectEvaluator.java:68)
    at org.gradle.configuration.project.LifecycleProjectEvaluator.access$400(LifecycleProjectEvaluator.java:51)
    at org.gradle.configuration.project.LifecycleProjectEvaluator$EvaluateProject.lambda$run$0(LifecycleProjectEvaluator.java:102)
    at org.gradle.api.internal.project.DefaultProjectStateRegistry$ProjectStateImpl.lambda$applyToMutableState$0(DefaultProjectStateRegistry.java:325)
    org.gradle.internal.concurrent.ThreadFactoryImpl$ManagedThreadRunnable.run(ThreadFactoryImpl.java:61)
Caused by: org.gradle.api.InvalidUserCodeException: Using insecure protocols with repositories, without explicit opt-in, is unsupported. Switch Maven repository 'BintrayJCenter2(http://jcenter.bintray.com/)' to redirect to a secure protocol (like HTTPS) or allow insecure protocols. See https://docs.gradle.org/7.2/dsl/org.gradle.api.artifacts.repositories.UrlArtifactRepository.html#org.gradle.api.artifacts.repositories.UrlArtifactRepository:allowInsecureProtocol for more details.

settings.gradle

代码语言:javascript
运行
复制
rootProject.name = 'Rent In Cars'

apply from: '../node_modules/react-native-unimodules/gradle.groovy'
includeUnimodulesProjects()

apply from: file("../node_modules/@react-native-community/cli-platform-android/native_modules.gradle");
applyNativeModulesSettingsGradle(settings)

include ':app'
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-11-13 15:57:01

解决方案1:删除jcenter()

首先,现在不推荐使用jcenter()存储库,所以尽量不要使用它。删除jcenter()的所有实例,问题就会得到解决。添加mavenCentral()作为替代。

解决方案2:允许jcenter()的不安全协议

在您提到jcenter()的任何地方,都可以这样扩展它:

Groovy DSL:

代码语言:javascript
运行
复制
jcenter() {
  allowInsecureProtocol = true
}

Kotlin DSL:

代码语言:javascript
运行
复制
jcenter() {
  isAllowInsecureProtocol = true
}
票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69955064

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档