每当我打开 android studio 时,Gradle 同步都会失败。这是我的 gradle.build 文件。有人可以告诉我如何解决这个问题吗?我安装了 gradle 7.2。但我不知道是什么导致了这个问题。我什至试过 allowInsecureProtocol = true
gradle.build/android
// 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
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')}"
}
这是我得到的错误 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 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'
最佳答案
解决方案 1:删除 jcenter()
首先,jcenter()
存储库现在已弃用,因此请尽量不要使用它。删除 jcenter()
的所有实例问题应该得到解决。添加 mavenCentral()
作为替代品。
解决方案 2:允许 jcenter()
使用不安全协议(protocol)
你提到的所有地方jcenter()
, 展开如下:
Groovy DSL:
jcenter() {
allowInsecureProtocol = true
}
Kotlin DSL:jcenter() {
isAllowInsecureProtocol = true
}
关于android - Gradle 同步失败 : Using insecure protocols with repositories, 没有明确选择加入,不受支持。切换 Maven 存储库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69955064/