How to solve Received status code 401 from server: Unauthorized problem?

2.7k Views Asked by At

How to fix 401 Problem, I try to implement autoimageSlider and it done successfully but when i upgrade my android studio version with latest one i got this kind of errrors. and I also tried to switch to offline mode from gradle but nothing works for me Please help me

build.gradle(Project:)

    buildscript {
        repositories {
            google()
            mavenCentral()
        }
        dependencies {
            classpath 'com.android.tools.build:gradle:4.2.2'
            classpath 'com.google.gms:google-services:4.3.8'
        }
    }
    
    allprojects {
        repositories {
            google()
            mavenCentral()
            maven { url "https://www.jitpack.io" }
        }
    }
    
    task clean(type: Delete) {
        delete rootProject.buildDir
    }

    Could not HEAD 

builde.gradle(Module)

  plugins {
        id 'com.android.application'
        id 'com.google.gms.google-services'
    }
    android {
        compileSdkVersion 30
        buildToolsVersion '30.0.3'
    
        defaultConfig {
            applicationId "com.example.mycollege"
            minSdkVersion 16
            targetSdkVersion 30
            versionCode 1
            versionName "1.0"
            multiDexEnabled true
            testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        }
    
        buildTypes {
            release {
                minifyEnabled false
                proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
            }
        }
        compileOptions {
            sourceCompatibility JavaVersion.VERSION_1_8
            targetCompatibility JavaVersion.VERSION_1_8
        }
    }
    
    dependencies {
    
        implementation 'androidx.appcompat:appcompat:1.3.0'
        implementation 'com.google.android.material:material:1.4.0'
        implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
        implementation 'androidx.navigation:navigation-fragment:2.3.5'
        implementation 'androidx.multidex:multidex:2.0.1'
        implementation 'com.facebook.android:facebook-android-sdk:11.0.0'
        implementation 'com.github.bumptech.glide:glide:4.12.0'
        implementation 'androidx.legacy:legacy-support-v4:1.0.0'
        implementation 'com.github.smarteist:autoimageslider:1.4.0'
        implementation 'com.github.barteksc:android-pdf-viewer:3.2.0-beta.1'
        implementation 'org.jetbrains:annotations:21.0.1'
        implementation 'de.hdodenhof:circleimageview:3.1.0'
        testImplementation 'junit:junit:4.13.2'
        androidTestImplementation 'androidx.test.ext:junit:1.1.3'
        androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
    }

Errors

'https://www.jitpack.io/com/github/smarteist/autoimageslider/1.4.0/autoimageslider-1.4.0.pom'. Received status code 401 from server: Unauthorized
    Disable Gradle 'offline mode' and sync project
1

There are 1 best solutions below

0
On

Try adding the below code in the top-level build.gradle file

pluginManagement {

    repositories {
        maven {
            url 'https://jitpack.io'
        }
    }
}

Reference: https://docs.gradle.org/current/userguide/plugins.html#sec:subprojects_plugins_dsl

I have also added the below in settings.gradle

dependencyResolutionManagement {

    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        google()
        mavenCentral()
        maven { url 'https://jitpack.io' }
    }
}

After adding do invalidate caches and restart the app