Manhar
Manhar

Reputation: 117

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

I updated Android Studio recently and ever since I am having issues with building the apps. I get this error when I build the app:

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

After tons of Invalidate caches and Restart and Re-building the project the error goes away and it works fine, but as soon as I close Android Studio and open it again, the error comes up again.

I also get this error in Syncing the Gradle files:

ERROR: Unable to resolve dependency for ':app@debug/compileClasspath': Could not resolve com.android.support:support-v4:22.+. Show Details Affected Modules: app

This is my build Gradle file:

// 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
}

This is my Gradle file (Module: 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'

I am not able to understand what's going wrong. I would appreciate any help.

Upvotes: 4

Views: 741

Answers (2)

PradyumanDixit
PradyumanDixit

Reputation: 2375

I also faced the same error when I migrated to newer version of Android Studio after quite some time. The error is maybe due to some bug in newer version of android studio that makes it unable to build non androidX migrated projects.

I just one day casually migrated to androidX and the issue was fixed magically. I also filed a similar bug to yours and also stated that this caused the issue to be fixed.

To migrate to 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.

This fixed my issue permanently.

Upvotes: 1

shizhen
shizhen

Reputation: 12583

Try to add maven { url 'https://maven.google.com' } and 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.
    }
}

Note that google() and maven { url 'https://maven.google.com' } are different.

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

Upvotes: 1

Related Questions