Could not resolve com.android.support:support-v4:2

2019-05-10 22:24发布

问题:

I have just begun using Fabric by Twitter. After the changes that the plugin does to the files, when I build the project, I am getting this error.

Error:A problem occurred configuring project ':app'.
> Could not resolve all dependencies for configuration ':app:_debugCompile'.
   > Could not resolve com.android.support:support-v4:21.0.0.
     Required by:
         Tourist:app:unspecified > com.twitter.sdk.android:twitter:1.0.1 >     com.twitter.sdk.android:tweet-ui:1.0.1
      > Could not GET 'https://maven.fabric.io/repo/com/android/support/support-v4/21.0.0/support-    v4-21.0.0.pom'. Received status code 401 from server: Unauthorized

Here is the build.gradle

buildscript {
    repositories {
        maven { url 'https://maven.fabric.io/repo' }
    }

    dependencies {
        classpath 'io.fabric.tools:gradle:1.+'
    }
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'

repositories {
    maven { url 'https://maven.fabric.io/repo' }
}


android {
    compileSdkVersion 19
    buildToolsVersion "19.1.0"

    defaultConfig {
        applicationId "com.example.sona.tourist"
        minSdkVersion 15
        targetSdkVersion 19
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            runProguard false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    //compile 'com.android.support:support-v4:19.1.0'
    compile('com.twitter.sdk.android:twitter:1.0.1@aar') {
        transitive = true;
    }

}

I have tried removing https, knew it won't work, but still. I have tried adding mavenCentral() to the repositories. But no luck. Would be really grateful if someone could help me out.

回答1:

You should update support library and the support repository from SDK Manager, as Hemal said here

[https://stackoverflow.com/a/26959871/3625658][1]



回答2:

You could change the maven repo in you build.gradle from:

maven { url 'https://maven.fabric.io/repo' }

to

maven { url 'https://maven.fabric.io/public' }

Make sure you update the two references in your build.gradle file,

Found here: Fabric maven repo causes slow gradle builds



回答3:

Make some random changes in app\build.gradle and undo them then syn your project. Worked for me at least.



回答4:

Looks like maven repository, http://maven.fabric.io/repo needs authentication (Since it is giving 401: Unauthorized)

Please provide the credentials to the repository as :

repositories {
    maven { 
        url 'https://maven.fabric.io/repo' 
        credentials {
            username = "your username"
            password = "password here"
        }
    }

}