首页 > 解决方案 > 为什么自从我更新 Android Studio 后,我遇到了无法修复的问题?

问题描述

我最近更新了 Android Studio,因为我在构建应用程序时遇到了问题。构建应用程序时出现此错误:

无法获取“ https://www.jitpack.io/com/android/support/support-v4/maven-metadata.xml ”。从服务器收到状态码 401:未授权

在大量无效缓存以及重新启动和重新构建项目之后,错误消失并且工作正常,但是一旦我关闭 Android Studio 并再次打开它,错误就会再次出现。

我在同步 Gradle 文件时也收到此错误:

错误:无法解析“:app@debug/compileClasspath”的依赖关系:无法解析com.android.support:support-v4:22.+。显示详细信息 受影响的模块:app

这是我的构建 Gradle 文件:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {

repositories {
    google()
    jcenter()
}
dependencies {
    classpath 'com.android.tools.build:gradle:3.3.2'

    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
    classpath 'com.google.gms:google-services:4.2.0'
    }
}

allprojects {
repositories {
    google()
    jcenter()
    maven { url 'https://www.jitpack.io' }
    }
}

task clean(type: Delete) {
     delete rootProject.buildDir
}

这是我的 Gradle 文件(模块:app)

apply plugin: 'com.android.application'

android {
compileSdkVersion 28
defaultConfig {
    applicationId "com.app.myapp"
    minSdkVersion 19
    targetSdkVersion 28
    versionCode 1
    versionName "1.0"
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
    }
}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.google.android.gms:play-services-auth:16.0.1'
implementation 'com.google.firebase:firebase-messaging:17.5.0'
implementation 'com.google.firebase:firebase-core:16.0.8'
implementation 'com.google.firebase:firebase-auth:16.2.0'
implementation 'org.nanohttpd:nanohttpd:2.2.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.google.firebase:firebase-database:16.1.0'
implementation 'com.google.firebase:firebase-ml-vision:19.0.3'
implementation 'com.google.firebase:firebase-ml-vision-image-label-model:17.0.2'
implementation 'com.google.code.gson:gson:2.8.2'
implementation 'com.melnykov:floatingactionbutton:1.3.0'
implementation 'com.github.vajro:MaterialDesignLibrary:1.6'
implementation 'com.github.devendroid:SquareMenu:1.0.0'
implementation 'org.aviran.cookiebar2:cookiebar2:1.1.1'
//implementation 'com.github.navasmdc:MaterialDesign:1.5@aar' // this was the reason for duplicated value error
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
}

apply plugin: 'com.google.gms.google-services'

我无法理解出了什么问题。我将不胜感激任何帮助。

标签: androidgradleandroid-gradle-plugin

解决方案


尝试添加maven { url 'https://maven.google.com' }maven { url "https://jitpack.io" } // <-- and try to use this.

allprojects {
    repositories {
        google()
        jcenter()
        maven { url 'https://maven.google.com' } // <-- add this.
        maven { url "https://jitpack.io" } // <-- and try to use this.
    }
}

注意google()maven { url 'https://maven.google.com' }是不同的。

google()https://dl.google.com/dl/android/maven2/


推荐阅读