为什么我在更新 Android Studio 后遇到无法修复的问题?

Why am I having un-fixable issues ever since I updated Android Studio?

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

Could not GET 'https://www.jitpack.io/com/android/support/support-v4/maven-metadata.xml'. Received status code 401 from server: Unauthorized

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

我在同步 Gradle 文件时也遇到了这个错误:

ERROR: Unable to resolve dependency for ':app@debug/compileClasspath': Could not resolve com.android.support:support-v4:22.+. Show Details Affected Modules: 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'

我不明白出了什么问题。如果有任何帮助,我将不胜感激。

尝试添加 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/.

我在一段时间后迁移到更新版本的 Android Studio 时也遇到了同样的错误。该错误可能是由于较新版本的 android studio 中的一些错误导致它无法构建非 androidX 迁移的项目。

我只是有一天随便迁移到 androidX,问题就神奇地解决了。我还提交了一个与您的类似的错误,并表示这导致问题得到解决。

要迁移到 androidX:

Go to Refractor from top menu the click migrate to androidX..
Also don't forget to check the backup your project in zip in case the migration fails.
Refractor the changes it suggests during migration and you're all done.

这永久解决了我的问题。